Jquery和JS实现浏览器全屏

var fullscreen=function(){  
    elem=document.body;  
    if(elem.webkitRequestFullScreen){  
        elem.webkitRequestFullScreen();     
    }else if(elem.mozRequestFullScreen){  
        elem.mozRequestFullScreen();  
    }else if(elem.requestFullScreen){  
        elem.requestFullscreen();  
    }else{  
        //浏览器不支持全屏API或已被禁用  
    }  
}  
var exitFullscreen=function(){  
    var elem=document;  
    if(elem.webkitCancelFullScreen){  
        elem.webkitCancelFullScreen();      
    }else if(elem.mozCancelFullScreen){  
        elem.mozCancelFullScreen();  
    }else if(elem.cancelFullScreen){  
        elem.cancelFullScreen();  
    }else if(elem.exitFullscreen){  
        elem.exitFullscreen();  
    }else{  
        //浏览器不支持全屏API或已被禁用  
    }  
}  
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(); 
} 
if (document.exitFullscreen) { 
document.exitFullscreen(); 
} 
else if (document.mozCancelFullScreen) { 
document.mozCancelFullScreen(); 
} 
else if (document.webkitCancelFullScreen) { 
document.webkitCancelFullScreen(); 
} 
else if (document.msExitFullscreen) { 
document.msExitFullscreen(); 
} 

 

posted @ 2015-10-20 09:14  贝尔格里尔斯  阅读(1750)  评论(0编辑  收藏  举报