JS实现浏览器全屏

JavaScript021

JS实现浏览器全屏,第1张

注解:ele要全屏的元素

退出全屏直接使用document调用exitFullscreen方法即可。

document.fullscreenElement():获取当前全屏的元素。

注意:

1.document下没有requestFullscreen

2.requestFullscreen方法只能由用户触发,比如:在onload事件中不能触发

3.页面跳转需先退出全屏

4.进入全屏的元素,将脱离其父元素,所以可能导致某些css失效

解决方案:使用 :full-screen伪类 为元素添加全屏时的样式(使用时为了兼容注意添加-webkit、-moz或-ms前缀)

5.一个元素全屏后,其子元素要再全屏,需先让该元素退出全屏

//你看一下,这个可以吗!

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}") 

}

您好!很高兴为您答疑!

实现窗口全屏(F11效果),只需在下面属性中加一条fullscreen = yes即可

<script>

<!--

function windowopen(){

var target="http://play.zol.com.cn"

newwindow=window.open("","","scrollbars")

if (document.all){

newwindow.moveTo(0,0)

newwindow.resizeTo(screen.width,screen.height)

}

newwindow.location=target

}

//-->

</script>

<form>

<input type="button" onClick="windowopen()" value="全屏显示" name="button">

</form>

您可以在火狐社区了解更多内容。希望我的回答对您有所帮助,如有疑问,欢迎继续在本平台咨询。