全屏展示js代码

  1. 全屏
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
    .a {
        margin:0 auto;
        height:600px;
        width:700px;
    }
    .content {
        margin:0 auto;
        height:500px;
        width:700px;
        background:#900;
    }
</style>
<body>
    <div class="a">
        <button id="btn">js控制页面的全屏展示</button>
        <div class="content" id="content">
            <h1 id="h1">js控制页面的全屏展示和退出全屏显示</h1>
            <button id="btn" onclick="exitFull()">js控制页面的退出全屏显示</button>
        </div>
    </div>
</body>
<script type="text/javaScript">
document.getElementById("btn").onclick=function(){
    var elem = document.getElementById("content");
    var h1 = document.getElementById("h1");
    requestFullScreen(elem);// 某个页面元素
    // requestFullScreen(document.documentElement);// 整个网页
};
function requestFullScreen(element) {
    // 判断各种浏览器,找到正确的方法
    var requestMethod = element.requestFullScreen || //W3C
    element.webkitRequestFullScreen ||    //Chrome等
    element.mozRequestFullScreen || //FireFox
    element.msRequestFullScreen; //IE11
    if (requestMethod) {
        requestMethod.call(element);
    }else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript !== null) {
            wscript.SendKeys("{F11}");
        }
    }
}
//退出全屏 判断浏览器种类
function exitFull() {
    // 判断各种浏览器,找到正确的方法
    var exitMethod = document.exitFullscreen || //W3C
    document.mozCancelFullScreen ||    //Chrome等
    document.webkitExitFullscreen || //FireFox
    document.webkitExitFullscreen; //IE11
    if (exitMethod) {
        exitMethod.call(document);
    }else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript !== null) {
            wscript.SendKeys("{F11}");
        }
    }
}
</script>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 工厂模式类似于现实生活中的工厂可以产生大量相似的商品,去做同样的事情,实现同样的效果;这时候需要使用工厂模式。简单...
    舟渔行舟阅读 7,842评论 2 17
  • 以下是常用的代码收集,学习用。转自豪情博客园 1. PC - js 返回指定范围的随机数(m-n之间)的公式 re...
    自由加咖啡阅读 1,026评论 0 1
  • (一)知识点 1.1属性 element.className element对象的class字符串数组,每个字符...
    Zvit阅读 466评论 0 0
  • 单例模式 适用场景:可能会在场景中使用到对象,但只有一个实例,加载时并不主动创建,需要时才创建 最常见的单例模式,...
    Obeing阅读 2,104评论 1 10
  • 相信对于一些开发者,这个词并不陌生,而且面试中经常会被问到。开发过程中我们也会经常用到,单例、延时、遍历、异步操作...
    会飞的大马猴阅读 761评论 0 11