HTML5 中fullscreen 中的几个API和fullscreen欺骗

HTML 5中的full screen,目前可以在除IE和opera外的浏览器中使用 ,有的时候用来做 
全屏API,游戏呀,等都很有用。先看常见的API 

1 element.requestFullScreen() 

    作用:请求某个元素element全屏 


Document.getElementById(“myCanvas”).requestFullScreen() 

  这里是将其中的元素ID去请求fullscreen 


退出全屏 
  document.cancelFullScreen() 


Document.fullScreen 

  如果用户在全屏模式下,则返回true 
5 document.fullScreenElement 
  返回当前处于全屏模式下的元素 

   下面的代码是开启全屏模式: 
Java代码    收藏代码
  1. function fullScreen(element) {  
  2.   if(element.requestFullScreen) {  
  3.     element.requestFullScreen();  
  4.   } else if(element.webkitRequestFullScreen ) {  
  5.     element.webkitRequestFullScreen();  
  6.   } else if(element.mozRequestFullScreen) {  
  7.     element.mozRequestFullScreen();  
  8.   }  
  9. }  


    下面的代码就是整个页面调用全屏模式 
  var html = document.documentElement; 
fullScreen(html); 
   下面的则是对指定元素,比如 
  var canvas = document.getElementById('mycanvas'); 
fullScreen(canvas); 
   如果要取消,同样: 
  
Java代码    收藏代码
  1. // the helper function  
  2. function fullScreenCancel() {  
  3.   if(document.requestFullScreen) {  
  4.     document.requestFullScreen();  
  5.   } else if(document .webkitRequestFullScreen ) {  
  6.     document.webkitRequestFullScreen();  
  7.   } else if(document .mozRequestFullScreen) {  
  8.     document.mozRequestFullScreen();  
  9.   }  
  10. }  
  11.   
  12.   
  13. fullScreenCancel();  


    不过老实说,FULL SCREEN有个问题,容易造成欺骗,比如在 
http://feross.org/html5-fullscreen-api-attack/中,其中就有一个很好的DEMO, 
去欺骗了,比如某个链结写的是http://www.bankofamerica.com,大家以为是美国银行, 
一点进去,因为使用了全屏幕API,就会欺骗到人 
 
Java代码    收藏代码
  1. $('html').on('click keypress''a', function(event) {  
  2.   
  3.   // 不响应真正的A HREF点击事件  
  4.   event.preventDefault();  
  5.   event.stopPropagation();  
  6.   
  7.   // Trigger fullscreen  
  8.   if (elementPrototype.requestFullscreen) {  
  9.     document.documentElement.requestFullscreen();  
  10.   } else if (elementPrototype.webkitRequestFullScreen) {  
  11.     document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);  
  12.   } else if (elementPrototype.mozRequestFullScreen) {  
  13.     document.documentElement.mozRequestFullScreen();  
  14.   } else {  
  15.     //  
  16.   }  
  17.   
  18.   //显示假的UI  
  19.   $('#menu, #browser').show();  
  20.   
  21.     
  22.   $('#target-site').show();  
  23. });  


  详细代码在https://github.com/feross/fullscreen-api-attack可以下载 
老外也提到了: 
   Browser vendors are well aware of the potential security issues with fullscreen. For example, a malicious site could show a full screen Windows or Mac login window and steal a password. That’s why they are disabling keyboard support by default and only enabling by explicitly asking. — John Dyer 

转载于:https://my.oschina.net/jackyrong/blog/114086

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值