ie浏览器中用js获取navigator.cookieEnabled总为true

最近因为项目上的需要须判断用户是否禁用了js和cookie,判断是否禁用cookie时的代码如下:

function CookieEnable(){        

        var result=false;         
        if(navigator.cookieEnabled)return true;             
        document.cookie = "testcookie=yes;";                 
        var cookieSet = document.cookie;            
        if (cookieSet.indexOf("testcookie=yes") > -1){
            var exp = new Date();
            exp.setTime(exp.getTime() - 1);            
            document.cookie = 'testcookie' + "=" + '' + "; expires=" + exp.toGMTString();//删除测试cookie
            result=true;           
        }          
        return result;   
    }   
 
    if(!CookieEnable()){   
        alert("对不起,您的浏览器的Cookie功能被禁用,请开启");         

    }

    用火狐和chrome浏览器测试正常通过,但用ie浏览器即使禁用了cookie仍无法检测出来,后来百度&google了好久发现当使用file://url这样的地址时,js在ie浏览器中测试的结果是不可靠的,需要用http://?????这样的website地址。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Vue中使用`navigator.mediaDevices.getUserMedia`来创建一个可调控大小的相机可以通过以下步骤实现: 1. 首先,在Vue组件中引入`navigator.mediaDevices.getUserMedia`方法。可以在组件的`mounted`生命周期钩子函数中添加以下代码: ```javascript mounted() { navigator.mediaDevices.getUserMedia({ video: true }) .then(stream => { // 获取到视频流后的处理逻辑 }) .catch(error => { // 处理错误情况 }); } ``` 2. 在获取到视频流后,可以将视频流绑定到`<video>`标签上,以显示相机的实时画面。在Vue模板中添加以下代码: ```html <template> <div> <video ref="videoElement" autoplay></video> </div> </template> ``` 3. 在Vue组件的`mounted`生命周期钩子函数中,获取到`<video>`标签的DOM元素,并将视频流绑定到该元素上: ```javascript mounted() { navigator.mediaDevices.getUserMedia({ video: true }) .then(stream => { this.$refs.videoElement.srcObject = stream; }) .catch(error => { // 处理错误情况 }); } ``` 4. 现在,你可以在Vue组件中添加一些控制按钮或滑块,用于调整相机的大小。通过修改`<video>`标签的宽度和高度样式,可以实现相机大小的调控。例如: ```html <template> <div> <video ref="videoElement" autoplay :style="{ width: videoWidth + 'px', height: videoHeight + 'px' }"></video> <button @click="increaseSize">增加大小</button> <button @click="decreaseSize">减小大小</button> </div> </template> <script> export default { data() { return { videoWidth: 640, videoHeight: 480 }; }, methods: { increaseSize() { this.videoWidth += 100; this.videoHeight += 100; }, decreaseSize() { this.videoWidth -= 100; this.videoHeight -= 100; } }, mounted() { navigator.mediaDevices.getUserMedia({ video: true }) .then(stream => { this.$refs.videoElement.srcObject = stream; }) .catch(error => { // 处理错误情况 }); } }; </script> ``` 这样,你就可以在Vue中使用`navigator.mediaDevices.getUserMedia`来创建一个可调控大小的相机了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值