html5怎么关闭摄像头

html-css08

html5怎么关闭摄像头,第1张

html5中的video这个标签是引入视频的,通过navigator.getUserMedia去获取摄像头的视频流,所以要在事件里用关闭的代码都不能执行关闭摄像头,只有关闭网页,摄像头才关闭。

html5打开摄像头代码:

<!DOCTYPE html>

<html lang="zh-cn">

<head>

<meta content="text/htmlcharset=UTF-8" http-equiv="content-type">

<title>Smart Home - Camera</title>

<link href="css/main.css" rel="stylesheet" type="text/css">

<script src="js/jq.js"></script>

<script type="text/javascript">

/*

*/

function init(t){

accessLocalWebCam("camera_box")

}

// Normalizes window.URL

window.URL = window.URL || window.webkitURL || window.msURL || window.oURL

// Normalizes navigator.getUserMedia

navigator.getUserMedia = navigator.getUserMedia ||

navigator.webkitGetUserMedia|| navigator.mozGetUserMedia ||

navigator.msGetUserMedia

function isChromiumVersionLower() {

var ua = navigator.userAgent

var testChromium = ua.match(/AppleWebKit\/.* Chrome\/([\d.]+).* Safari\//)

return (testChromium &&(parseInt(testChromium[1].split('.')[0]) <19))

}

function successsCallback(stream) {

document.getElementById('camera_errbox').style.display = 'none'

document.getElementById('camera_box').src = (window.URL

&&window.URL.createObjectURL) ?

window.URL.createObjectURL(stream) : stream

}

function errorCallback(err) {

}

function accessLocalWebCam(id) {

try {

// Tries it with spec syntax

navigator.getUserMedia({ video: true }, successsCallback, errorCallback)

} catch (err) {

// Tries it with old spec of string syntax

navigator.getUserMedia('video', successsCallback, errorCallback)

}

}

</script>

<style type="text/css">

#camera_errbox{

width:320pxheight:autoborder:1px solid #333333padding:10px

color:#ffftext-align:leftmargin:20px auto

font-size:14px

}

#camera_errbox b{

padding-bottom:15px

}

</style>

</head>

<body onLoad="init(this)" oncontextmenu="return false" onselectstart="return false">

<div class="Screen_outer">

<div id="mainbox" class="Screen_inner">

<div id="bt_goback"></div>

<div class="logobox"></div><div id="t_iconbox"

class="icon_12"></div><div id="t_text">

<div id="el_title" class="font_h2">Camera</div>

<div id="el_descr" class="font_2"></div>

</div>

<div class="t_descri_bt"></div>

<div class="sp_title"><span

class="sp_title_text">Camera</span><div class="sp_oc

sp_oc_1"></div></div>

<dl id="el_actionbox" class="menu_btbox" style="text-align:center">

<video id="camera_box" autoplay="" src=""></video>

<div id="camera_errbox">

<b>请点击“允许”按钮,授权网页访问您的摄像头!</b>

<div>若您并未看到任何授权提示,则表示您的浏览器不支持Media Capture或您的机器没有连接摄像头设备。</div>

</div>

</dl>

</div>

</div>

</body>

</html>

关闭输入框的自动完成功能有3种方法:

1、在IE的Internet选项菜单里的内容--自动完成里面设置

2、设置Form的autocomplete为"on"或者"off"来开启或者关闭自动完成功能

3、设置输入框的autocomplete为"on"或者"off"来开启或者关闭该输入框的自动完成功能

找到IE浏览器Internet选项里的内容进行设置

2.设置Form元素的autocomplete为“on”或者“off”来开启或者关闭自动完成功能

3.设置input输入框的autocomplete为“on”或者“off”来开启或者关闭该输入框的自动完成功能(关闭密码域的自动完成)

代码实例:

<!-- 打开自动完成功能的Form  -->

<form name="form1" autocomplete="on">  

    <!-- 打开自动完成功能的输入框   -->

    <input type="text" autocomplete="on" name="user">  

    <!-- 关闭自动完成功能的输入框   -->

    <input type="password" autocomplete="off" name="password">

</form>  

<!-- 关闭自动完成功能的Form  -->

<form name="form1" autocomplete="off">  

    <!-- 打开自动完成功能的输入框   -->

    <input type="text" autocomplete="on" name="user"> 

    <!-- 关闭自动完成功能的输入框   -->

    <input type="password" autocomplete="off" name="password"> 

</form>

表单的更多内容详见:《form表单存在的常见兼容问题》