扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
试一下下面这个函数:
创新互联建站于2013年创立,先为定襄等服务建站,定襄等地企业,进行企业商务咨询服务。为定襄企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
function fullScreen() {
var el = document.documentElement;
var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen;
if (typeof rfs != "undefined" rfs) {
rfs.call(el);
} else if (typeof window.ActiveXObject != "undefined") {
// for Internet Explorer
var wscript = new ActiveXObject("WScript.Shell");
if (wscript != null) {
wscript.SendKeys("{F11}");
}
}
}
不用谢!
--使用screenfull.js 这个插件可以让任意浏览器全屏
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
script src=""/script
/head
body
button class="am-btn am-btn-primary" id="doc-fs-request" onclick="full()"全屏窗口/button
script type="text/javascript"
function full(){
var docElm = document.documentElement;
if (docElm.requestFullscreen) {
docElm.requestFullscreen();
}
else if (docElm.mozRequestFullScreen) {
docElm.mozRequestFullScreen();
}
else if (docElm.webkitRequestFullScreen) {
docElm.webkitRequestFullScreen();
}
}
/script
/body
/html
/**
* 全屏方法
*/
function fullScreen(domId){
var element = document.getElementById(domId);
// request fullScreen
this.request = function(){
if(element.requestFullScreen) {
element.requestFullScreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullScreen) {
// 对 Chrome 特殊处理,
// 参数 Element.ALLOW_KEYBOARD_INPUT 使全屏状态中可以键盘输入。
if ( window.navigator.userAgent.toUpperCase().indexOf( 'CHROME' ) = 0 ) {
element.webkitRequestFullScreen( Element.ALLOW_KEYBOARD_INPUT );
}
// Safari 浏览器中,如果方法内有参数,则 Fullscreen 功能不可用。
else {
element.webkitRequestFullScreen();
}
}else if(element.msRequestFullscreen){
element.msRequestFullscreen();
}else {
throw new Error("your browser doesn't support the fullScreen,please change or update it.");
}
console.log( element.style.zIndex);
return element.style.zIndex;
};
//取消全屏
this.cancelFullscreen = function() {
if(document.cancelFullScreen) {
document.cancelFullScreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if(document.msExitFullscreen){
document.msExitFullscreen();
} else{
throw new Error("your browser doesn't support the fullScreen,please change or update it.");
}
} ;
}
//判断当前状态是否为全屏
var isFullScreen = function(){
if(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement)
return true;
else
return false;
};
(function(){
var width= document.documentElement.clientWidth || window.innerWidth;
if( width==screen.availWidth){
alert("全屏");
}else{
alert("不是全屏");
}
})();
//刷新检测
window.open("XXX","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=4000, height=4000")
!doctype html
html
head
meta charset="utf-8"
title全屏/title
/head
body
/body
script type="text/javascript"
window.onload = function(){
var Request = new Array(); //保存参数
var s = location.search.substring(1);
if (s s != "") {
var list = s.split("");
for (var i = 0; i list.length; i++) {
var pair = list[i].split("=");
if (pair[0] pair[0] != "") {
Request[unescape(pair[0])] = unescape(pair[1]);
}
}
}
var fullscreen = Request["fullscreen"];
if (fullscreen != "yes") {
var file = self.location;
var a = window.open("about:blank", "", "fullscreen=yes");
self.opener = null;
self.close();
a.location = file + "?fullscreen=yes";
}
}
/script
/html
这个是比较早期的全屏代码,现在有纯正的全屏API,但浏览器兼容性很不好,只支持chrome和firefox最新版本浏览器,其它的都不支持,所以还是用这个吧。
上面的代码已经搞定,打开后会自动进入全屏模式,当然,必须要允许这个网页自动弹出窗口才行。
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流