浏览器全屏的JS代码实现
方法一:该方法是从一个网上的效果看到不错,然后自己就拿来下来实验了一下,还是比较满意度,下面直接给出代码
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>全屏</title> <script type="text/javascript"> (function(a, b) {
"use strict";
var c = function() {
var a = [["requestFullscreen", "exitFullscreen", "fullscreenchange", "fullscreen", "fullscreenElement"], ["webkitRequestFullScreen", "webkitCancelFullScreen", "webkitfullscreenchange", "webkitIsFullScreen", "webkitCurrentFullScreenElement"], ["mozRequestFullScreen", "mozCancelFullScreen", "mozfullscreenchange", "mozFullScreen", "mozFullScreenElement"]];
for (var c = 0,
d = a.length; c < d; c++) {
var e = a[c];
if (e[1] in b) return e
}
} ();
if (!c) return a.screenfull = !1;
var d = "ALLOW_KEYBOARD_INPUT" in Element,
e = {
init: function() {
return b.addEventListener(c[2],
function(a) {
e.isFullscreen = b[c[3]],
e.element = b[c[4]],
e.onchange(a)
}),
this
},
isFullscreen: b[c[3]],
element: b[c[4]],
request: function(a) { a = a || b.documentElement,
a[c[0]](d && Element.ALLOW_KEYBOARD_INPUT),
b.isFullscreen || a[c[0]]();
//alert("dd");
},
exit: function() {
b[c[1]]()
},
toggle: function(a) {
this.isFullscreen ? this.exit() : this.request(a)
},
onchange: function() {}
};
a.screenfull = e.init()
})(window, document) </script> </head>
<body>
<div id="loading" style="margin:10px auto;width:600px">正在加载...</div>
<div id="theEnd"></div> <script type="text/javascript"> function ck() {
screenfull && screenfull.request();
}; // 在这里写你的代码...
var loading = document.getElementById('loading');
loading.style.cursor = 'pointer';
loading.innerHTML = '点击开始';
loading.onclick = ck </script> </body>
</html>
上面的代码很简单,功能主要是在head中的script脚本代码---并且是经过我格式化后的代码,在body中的代码只是去调用。
说明:没有实验成功在页面打开的时候就直接全屏,不知道为什么必须要绑定到某个对象的onclick事件上来调用?
下面的是最开始未格式化的代码,应该是压缩过的
<script type="text/javascript">
(function(a,b){"use strict";var c=function(){var a=[["requestFullscreen","exitFullscreen","fullscreenchange","fullscreen","fullscreenElement"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitfullscreenchange","webkitIsFullScreen","webkitCurrentFullScreenElement"],["mozRequestFullScreen","mozCancelFullScreen","mozfullscreenchange","mozFullScreen","mozFullScreenElement"]];for(var c=0,d=a.length;c<d;c++){var e=a[c];if(e[1]in b)return e}}();if(!c)return a.screenfull=!1;var d="ALLOW_KEYBOARD_INPUT"in Element,e={init:function(){return b.addEventListener(c[2],function(a){e.isFullscreen=b[c[3]],e.element=b[c[4]],e.onchange(a)}),this},isFullscreen:b[c[3]],element:b[c[4]],request:function(a){a=a||b.documentElement,a[c[0]](d&&Element.ALLOW_KEYBOARD_INPUT),b.isFullscreen||a[c[0]]()},exit:function(){b[c[1]]()},toggle:function(a){this.isFullscreen?this.exit():this.request(a)},onchange:function(){}};a.screenfull=e.init()})(window,document)
</script>
具体怎么用,你就自己斟酌使用
================================================================================
方法二:
这个方法和方法一很类似,也是我从网上找来的,用来一下效果也还不错。
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>
<div style="margin:0 auto;height:600px;width:700px;">
<button id="btn">js控制页面的全屏展示和退出全屏显示</button>
<div id="content" style="margin:0 auto;height:500px;width:700px; background:#900;" >
<h1 id="h1">js控制页面的全屏展示和退出全屏显示</h1>
<button id="btn" onclick="exitFull()">js控制页面的退出全屏显示</button>
</div>
</div>
</body>
<script language="JavaScript"> document.getElementById("btn").onclick=function(){
var elem = document.getElementById("content");
var h1 = document.getElementById("h1");
requestFullScreen(elem);// 某个页面元素
//requestFullScreen(document.documentElement);// 整个网页
}; function requestFullScreen(element) {
// 判断各种浏览器,找到正确的方法
var requestMethod = element.requestFullScreen || //W3C
element.webkitRequestFullScreen || //Chrome等
element.mozRequestFullScreen || //FireFox
element.msRequestFullScreen; //IE11
if (requestMethod) {
requestMethod.call(element);
}
else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
} //退出全屏 判断浏览器种类
function exitFull() {
// 判断各种浏览器,找到正确的方法
var exitMethod = document.exitFullscreen || //W3C
document.mozCancelFullScreen || //Chrome等
document.webkitExitFullscreen || //FireFox
document.webkitExitFullscreen; //IE11
if (exitMethod) {
exitMethod.call(document);
}
else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
} </script>
</html>
说明:没有实验成功在页面打开的时候就直接全屏,不知道为什么必须要绑定到某个对象的onclick事件上来调用?
参考出处:
http://www.jb51.net/article/61940.htm
http://www.jb51.net/article/47038.htm
http://www.2cto.com/kf/201410/346205.html
================================================================================
方法三:这个方法有点牵强,我感觉其实就是指的最大化,你自己可以试试代码,并且我都做了一些说明
<!DOCTYPE html>
<html>
<HEAD>
<title>实现浏览器真正全屏的JS代码 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script language="javascript">
//ps:这是实现屏幕最大化 方法一
function openwin_max(url){
var scrWidth=screen.availWidth;
var scrHeight=screen.availHeight;
var self=window.open(url,"PowerBOS","resizable=1");
self.moveTo(-4,-4);
self.resizeTo(scrWidth+9,scrHeight+9);
}
// ps:这是实现窗口最大化 方法二
function openwin_full(url) {
var scrWidth=screen.availWidth;
var scrHeight=screen.availHeight;
var opt='top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no,fullscreen=1';
var self = window.open(url, "aaaa", opt);
//var self=window.open(url,"PowerBOS","resizable=1");
self.moveTo(0,0);
self.resizeTo(scrWidth,scrHeight);
}
</script> <script> window.moveTo(0,0);
window.resizeTo(screen.availWidth,screen.availHeight);
window.outerWidth=screen.availWidth;
window.outerHeight=screen.availHeight;
//这是实现屏幕最大化! 方法三
function fullScreen(){
var opt='top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no';
//window.open(document.location, 'aaa', 'fullscreen')
window.open(document.location, "aaa", opt);
} </script> </head>
<body> <input type="BUTTON" value="全屏显示一" onClick="openwin_max(document.location)">
<br />
<input type="BUTTON" value="全屏显示二" onClick="openwin_max(document.location)">
<br />
<input type="BUTTON" value="全屏显示三" onClick="fullScreen()">
<p style="font-size:16px; text-indent:2em; ">这个网页特代码实现了浏览器的最大化完全全屏</p>
<p style="font-size:16px; text-indent:2em; font-weight:bold; margin-top:30px;">
关闭方法: 按键盘 alt+f4 不过对于火狐浏览器不能完全全仍然显示地址栏和关闭按钮。 </p>
<p style="font-size:16px; text-indent:2em; font-weight:bold; margin-top:30px;">O(∩_∩)O哈哈~</p> </body>
</HTML>
网上有很多人说要将第三中方式的方法写到body的onload事件中可以实现页面在载人的时候就显示最大化 :如<body onload="fullScreen();">
我测试下来是有点问题的:
①:window.open(document.location, '', 'fullscreen')在该方法的第二个参数如果为空,在body的onload事件中是一个open指定页面的死循环的调用打开,也就是说会无限制的打开一个新的窗口,你可以自己测试,注意你的任务管理器的性能选项卡中CPU的变化。
②:如果给出window.open方法的第二个参数,例如:window.open(document.location, 'aaa', 'fullscreen'),则在body的onload事件中调用的的时候也是死循环,只是都是同一个页面窗口而已,你可以自己测试,注意你的任务管理器的性能选项卡中CPU的变化。
以上出现的问题,希望有兴趣的朋友自己研究下,并告诉我最好的解决方案
参考出处:
http://blog.sina.com.cn/s/blog_4f8f56850100c0ig.html
http://fluagen.blog.51cto.com/146595/186101
http://www.51xuediannao.com/js/texiao/IEquanping.html
================================================================================
浏览器全屏的JS代码实现的更多相关文章
- 页面全屏显示JS代码
1.直接在页面加载时就全屏. <body onload="window.open(document.location,'big','fullscreen=yes'):window.cl ...
- 浏览器全屏之requestFullScreen全屏与F11全屏
一.简介 浏览器全屏有两种方式,一种是HTML5新增的requestFullscree全屏,另一种是摁F11实现的全屏,本文将详解两种全屏的特点以及实现代码. 二.requestFullscreen全 ...
- 兼容IE浏览器的js浏览器全屏代码
众所周知,IE是个奇葩的浏览器,但是由于用户量很大,开发者还是不得不为IE考虑一下,于是,各种浏览器相关的操作,都要多一个特别的判断——专门针对IE浏览器的判断,这里的全屏也不例外.看代码: func ...
- js 实现各浏览器全屏
现代浏览器包括ie11,可以直接用h5的全屏api实现 低版本的IE需要通过ActiveX插件实现: 代码实现 <!DOCTYPE html> <html> <head& ...
- HTML5 JS 实现浏览器全屏(F11的效果)
项目中有需要使用JS来控制浏览器全屏的方法 DEMO地址: http://zhongxia245.github.io/demo/js2fullpanel.html function fullScree ...
- 用html5(requestFullscreen) js实现点击一个按钮使浏览器全屏效果
项目中需要将后台浏览器的窗口全屏,也就是我们点击一个按钮要实现按F11全屏的效果. 在HTML5中,W3C制定了关于全屏的API,就可以实现全屏幕的效果,也可以让页面中的图片,视频等全屏目前只有goo ...
- 用html5 js实现浏览器全屏
项目中需要将后台浏览器的窗口全屏,也就是我们点击一个按钮要实现按F11全屏的效果. 在HTML5中,W3C制定了关于全屏的API,就可以实现全屏幕的效果,也可以让页面中的图片,视频等全屏目前只有goo ...
- [JavaScript] 用html5 js实现浏览器全屏
项目中需要将后台浏览器的窗口全屏,也就是我们点击一个按钮要实现按F11全屏的 效果. 在HTML5中,W3C制定了关于全屏的API,就可以实现全屏幕的效果,也可以 让页面中的图片,视频等全屏目前只有g ...
- html5 js实现浏览器全屏
全屏 var docElm = document.documentElement; //W3C if (docElm.requestFullscreen) { docElm.requestFullsc ...
随机推荐
- 【BZOJ1109】[POI2007]堆积木Klo 二维偏序
[BZOJ1109][POI2007]堆积木Klo Description Mary在她的生日礼物中有一些积木.那些积木都是相同大小的立方体.每个积木上面都有一个数.Mary用他的所有积木垒了一个高塔 ...
- php解析xml文件为数组
$xml = simplexml_load_file($fullfilename); $arr = json_decode(json_encode($xml),true); echo "&l ...
- python-安装 pip
https://pip.pypa.io/en/stable/installing/ wget https://bootstrap.pypa.io/get-pip.py python get-pip.p ...
- R语言图形base系统(一)
一般R作图有三大绘图系统:base系统.ggplot2绘图系统.lattice绘图系统. 本篇主要介绍base系统绘图时的图形参数.一般用plot()函数来完成.在R中,若 ...
- python2 生成验证码图片
使用pillow或者pil库编写 #coding:utf-8 #use pillow or pil try: from PIL import Image, ImageDraw, ImageFont, ...
- 【HTTP】初识代理
Web代理(proxy)位于客户端和服务器端之间.HTTP的代理服务器既是Web服务器端又是Web客户端. 1. 代理和网关的对比 代理连接的是两个或者多个使用相同协议的应用程序. 网关连接的是两个或 ...
- python基础14 ---函数模块4(configparser模块)
configparser模块 一.configparser模块 1.什么是configparser模块:configparser模块操作配置文件,配置文件的格式与windows ini和linux的c ...
- Pinpoint扩展插件实践笔记
为链路(spanEvent)添加tag 背景 我们可能需要想在代码中写入特定的信息到调用链中,并且希望对里面的特定key做检索 实现思路 创建一个特定的类,只需要一个方法,再对这个类的方法进行增强,这 ...
- HR_ROS 节点信息
https://stackoverflow.com/questions/24638063/install-node-serialport-module-on-arm-linux https://blo ...
- spring mvc入门教程 转载自【http://elf8848.iteye.com/blog/875830】
目录 一.前言二.spring mvc 核心类与接口三.spring mvc 核心流程图 四.spring mvc DispatcherServlet说明 五.spring mvc 父子上下文的说明 ...