全屏展示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);// 整個網(wǎng)頁
};
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>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 工廠模式類似于現(xiàn)實生活中的工廠可以產(chǎn)生大量相似的商品,去做同樣的事情,實現(xiàn)同樣的效果;這時候需要使用工廠模式。簡單...
    舟漁行舟閱讀 8,118評論 2 17
  • 以下是常用的代碼收集,學(xué)習(xí)用。轉(zhuǎn)自豪情博客園 1. PC - js 返回指定范圍的隨機(jī)數(shù)(m-n之間)的公式 re...
    自由加咖啡閱讀 1,104評論 0 1
  • (一)知識點(diǎn) 1.1屬性 element.className element對象的class字符串?dāng)?shù)組,每個字符...
    Zvit閱讀 486評論 0 0
  • 單例模式 適用場景:可能會在場景中使用到對象,但只有一個實例,加載時并不主動創(chuàng)建,需要時才創(chuàng)建 最常見的單例模式,...
    Obeing閱讀 2,314評論 1 10
  • 相信對于一些開發(fā)者,這個詞并不陌生,而且面試中經(jīng)常會被問到。開發(fā)過程中我們也會經(jīng)常用到,單例、延時、遍歷、異步操作...
    會飛的大馬猴閱讀 803評論 0 11

友情鏈接更多精彩內(nèi)容