html5 js 实现浏览器全屏效果(F11)


           最近项目中需要浏览器全屏的效果、我查了很多资料、终于、找到了一段代码、说是能兼容google chrome 15 +, safri5.1+,firfox10+,IE11支持 、我只试验了火狐可以、360、以及IE8是没有成功滴、下面给大家发下代码、复制到HTML的页面就可以实现啦!


<input id="Button1" type="button" value="开始全屏" onclick="kaishi()" />
<input id="Button2" type="button" value="关闭全屏" onclick="guanbi()" />

<script>
    function kaishi()
    {


        var docElm = document.documentElement;
        //W3C 
        if (docElm.requestFullscreen) {
            docElm.requestFullscreen();
        }
            //FireFox 
        else if (docElm.mozRequestFullScreen) {
            docElm.mozRequestFullScreen();
        }
            //Chrome等 
        else if (docElm.webkitRequestFullScreen) {
            docElm.webkitRequestFullScreen();
        }
            //IE11 
        else if (elem.msRequestFullscreen) {
            elem.msRequestFullscreen();
        }
    }

    function guanbi() {


        if (document.exitFullscreen) {
            document.exitFullscreen();
        }
        else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        }
        else if (document.webkitCancelFullScreen) {
            document.webkitCancelFullScreen();
        }
        else if (document.msExitFullscreen) {
            document.msExitFullscreen();
        }
    }




    document.addEventListener("fullscreenchange", function () {
        
        fullscreenState.innerHTML = (document.fullscreen) ? "" : "not ";
    }, false);
   

    
    document.addEventListener("mozfullscreenchange", function () {
       
        fullscreenState.innerHTML = (document.mozFullScreen) ? "" : "not ";
    }, false);
    

   
    document.addEventListener("webkitfullscreenchange", function () {
        
        fullscreenState.innerHTML = (document.webkitIsFullScreen) ? "" : "not ";
    }, false);
    
    document.addEventListener("msfullscreenchange", function () {
        
        fullscreenState.innerHTML = (document.msFullscreenElement) ? "" : "not ";
    }, false);




</script>



出处:http://camnpr.com/javascript/1141.html

最近做项目忙死了……………………

————————————————————chenchen好久没冒泡了——————————————————————

你可能感兴趣的:(html5 js 实现浏览器全屏效果(F11))