document.getElementById("btn").onclick=function(){ var elem = document.getElementById("content"); ???requestFullScreen(elem); ???/* ????注意这里的样式的设置表示全屏显示之后的样式, ????退出全屏后样式还在, ????若要回到原来样式,需在退出全屏里把样式还原回去 ????(见写法三) ????*/ ???elem.style.height = ‘800px‘; ???elem.style.width = ‘100%‘; }; function requestFullScreen(element) { var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen; ? if (requestMethod) { ???? requestMethod.call(element); ? }else if (typeof window.ActiveXObject !== "undefined") { ?? var wscript = new ActiveXObject("WScript.Shell"); ?? ?if (wscript !== null) { ??? wscript.SendKeys("{F11}"); ? ??} ????} }代码来源:http://www.jb51.net/article/101692.htm。
这个可以使选定的内容全屏而不是页面上所有的内容全屏,不过这个有个缺点是高度不能铺满。
js实现全屏
原文地址:https://www.cnblogs.com/yaoya/p/8350561.html