程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> javascript-js點擊某一個鏈接交替執行兩個函數(js實現網頁全屏問題)

javascript-js點擊某一個鏈接交替執行兩個函數(js實現網頁全屏問題)

編輯:編程綜合問答
js點擊某一個鏈接交替執行兩個函數(js實現網頁全屏問題)

想實現的需求:
1、網頁上有個“全屏顯示”按鈕(鏈接),點擊全屏後執行函數fullScreen(),然後“顯示全屏”二字變成“退出全屏”;
2、點擊“退出全屏”執行函數exitFullScreen(),然後“退出全屏”變為“全屏顯示”

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 IE,這裡其實就是模擬了按下鍵盤的F11,使浏覽器全屏
var wscript = new ActiveXObject("WScript.Shell");
if(wscript != null) {
wscript.SendKeys("{F11}");
}
}
}
function exitFullScreen() {
var el = document;
var cfs = el.cancelFullScreen || el.webkitCancelFullScreen ||
el.mozCancelFullScreen || el.exitFullScreen;
if(typeof cfs != "undefined" && cfs) {
cfs.call(el);
} else if(typeof window.ActiveXObject != "undefined") {
//for IE,這裡和fullScreen相同,模擬按下F11鍵退出全屏
var wscript = new ActiveXObject("WScript.Shell");
if(wscript != null) {
wscript.SendKeys("{F11}");
}
}
}

最佳回答:


 <a href="#" onclick="return ExecuteFun(this)">全屏顯示</a>
<script>
    function ExecuteFun(a) {
        var full = a.innerHTML == '全屏顯示';
        full ? fullScreen() : exitFullScreen();
        a.innerHTML = full ? '退出全屏' : '全屏顯示';
        return false;
    }
    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 IE,這裡其實就是模擬了按下鍵盤的F11,使浏覽器全屏
            var wscript = new ActiveXObject("WScript.Shell");
            if (wscript != null) {
                wscript.SendKeys("{F11}");
            }
        }
    }
    function exitFullScreen() {
        var el = document;
        var cfs = el.cancelFullScreen || el.webkitCancelFullScreen ||
        el.mozCancelFullScreen || el.exitFullScreen;
        if (typeof cfs != "undefined" && cfs) {
            cfs.call(el);
        } else if (typeof window.ActiveXObject != "undefined") {
            //for IE,這裡和fullScreen相同,模擬按下F11鍵退出全屏
            var wscript = new ActiveXObject("WScript.Shell");
            if (wscript != null) {
                wscript.SendKeys("{F11}");
            }
        }
    }
</script>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved