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 
  返回当前处于全屏模式下的元素

下面的代码是开启全屏模式:

  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); 
   如果要取消,同样:

  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. fullScreenCancel();

不过老实说,FULL SCREEN有个问题,容易造成欺骗,比如在 
http://feross.org/html5-fullscreen-api-attack/中,其中就有一个很好的DEMO, 
去欺骗了,比如某个链结写的是http://www.bankofamerica.com,大家以为是美国银行, 
一点进去,因为使用了全屏幕API,就会欺骗到人

  1. $('html').on('click keypress', 'a', function(event) {
  2. // 不响应真正的A HREF点击事件
  3. event.preventDefault();
  4. event.stopPropagation();
  5. // Trigger fullscreen
  6. if (elementPrototype.requestFullscreen) {
  7. document.documentElement.requestFullscreen();
  8. } else if (elementPrototype.webkitRequestFullScreen) {
  9. document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  10. } else if (elementPrototype.mozRequestFullScreen) {
  11. document.documentElement.mozRequestFullScreen();
  12. } else {
  13. //
  14. }
  15. //显示假的UI
  16. $('#menu, #browser').show();
  17. $('#target-site').show();
  18. });

详细代码在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

使用javascript实现浏览器全屏的更多相关文章

  1. [转] JavaScript控制浏览器全屏及各种浏览器全屏模式的方法、属性和事件

    [From] http://www.jb51.net/article/76695.htm HTML 5中的full screen,目前可以在除IE和opera外的浏览器中使用 ,有的时候用来做全屏AP ...

  2. JavaScript控制浏览器全屏及各种浏览器全屏模式的方法、属性和事件

    实现全屏 个人版:function isFullScreen() { var fullscreenElement = document.fullscreenElement || document.we ...

  3. JavaScript:让浏览器全屏显示

    并不是所有人都会按F11让浏览器全屏显示~~~ 一.直接上代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xh ...

  4. [JavaScript] 用html5 js实现浏览器全屏

    项目中需要将后台浏览器的窗口全屏,也就是我们点击一个按钮要实现按F11全屏的 效果. 在HTML5中,W3C制定了关于全屏的API,就可以实现全屏幕的效果,也可以 让页面中的图片,视频等全屏目前只有g ...

  5. 兼容IE浏览器的js浏览器全屏代码

    众所周知,IE是个奇葩的浏览器,但是由于用户量很大,开发者还是不得不为IE考虑一下,于是,各种浏览器相关的操作,都要多一个特别的判断——专门针对IE浏览器的判断,这里的全屏也不例外.看代码: func ...

  6. javascript full screen 全屏显示 页面元素

    javascript full screen 全屏显示 页面元素 要想让页面的某个元素全屏显示,就像在网页上看视频的时候,可以全屏观看一样,该怎么实现呢? 一种最简单的方式,就是动态改变你想要全屏显示 ...

  7. js 实现各浏览器全屏

    现代浏览器包括ie11,可以直接用h5的全屏api实现 低版本的IE需要通过ActiveX插件实现: 代码实现 <!DOCTYPE html> <html> <head& ...

  8. jsp实现浏览器全屏

    在web系统中实现按钮控制浏览器全屏. <!DOCTYPE html> <%@ page contentType="text/html;charset=UTF-8" ...

  9. 用html5 js实现浏览器全屏

    项目中需要将后台浏览器的窗口全屏,也就是我们点击一个按钮要实现按F11全屏的效果. 在HTML5中,W3C制定了关于全屏的API,就可以实现全屏幕的效果,也可以让页面中的图片,视频等全屏目前只有goo ...

随机推荐

  1. php正则表达式入门-常用语法格式

    php正则表达式入门-常用语法格式 原文地址:http://www.jbxue.com/article/24467.html 分享下php正则表达式中的一些常用语法格式,用于匹配字母.数字等,个人感觉 ...

  2. vivado2015.4 simulator 存储所有信号到 .wdb 文件 并打开波形文件查看波形

    OS WIN7vivado 2015.4vivado自带的仿真器 vivado project 包含一个block design, block design 中包含AXIPCIE, MIG, INTE ...

  3. [转载]关于generate用法的总结【Verilog】

    转载自http://www.cnblogs.com/nanoty/archive/2012/11/13/2768933.html Abtract generate语句允许细化时间(Elaboratio ...

  4. HTML5学习笔记(六):CSS基本样式

    背景 需要注意:背景的所有属性都不会向下进行继承. 背景色 我们可以设定一个纯色为背景色. p {background-color: red;} a {background-color: #ff000 ...

  5. [Windows Azure] Walkthrough to Configure System Center Management Pack for Windows Azure Fabric Preview for SCOM 2012 SP1 (with a MetricsHub Bonus)

    The wait is finally over. This is a huge update to the Azure Management Pack over the one that was r ...

  6. [Windows Azure] Getting Started with Windows Azure SQL Data Sync

    Getting Started with Windows Azure SQL Data Sync In this tutorial, you learn the fundamentals of Win ...

  7. [Windows Azure] Building worker role B (email sender) for the Windows Azure Email Service application - 5 of 5.

    Building worker role B (email sender) for the Windows Azure Email Service application - 5 of 5. This ...

  8. Android 编程下通过 Theme 和 Style 避免 APP 启动闪黑屏

    之前在做 APP 的时候不太关注这个问题,因为自己在使用其他 APP 的时候也会在应用启动的初始有一个黑屏闪过后才会出现应用的欢迎页.直到最近开发过程中发现自己在欢迎页启动的线程由于请求和处理的数据量 ...

  9. 【甘道夫】HBase基本数据操作详解【完整版,绝对精品】

    引言 之前详细写了一篇HBase过滤器的文章,今天把基础的表和数据相关操作补上. 本文档参考最新(截止2014年7月16日)的官方Ref Guide.Developer API编写. 所有代码均基于“ ...

  10. 【内核】内核链表使用说明,list.h注释

    list_entry定义 /** * list_entry - get the struct for this entry * @ptr: the &struct list_head poin ...