關於跨域Iframe裡不能全屏
阿新 • • 發佈:2020-08-27
區域性全屏方法
var btn = document.getElementById("btnFull"); btn.onclick = function () { var elem = document.getElementById("table-form"); requestFullScreen(elem); }; function requestFullScreen(element) { var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen; if (requestMethod) { requestMethod.call(element); } else if (typeof window.ActiveXObject !== "undefined") { var wscript = new ActiveXObject("WScript.Shell"); if (wscript !== null) { wscript.SendKeys("{F11}"); } } } function exitFullscreen() { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitExitFullscreen) { document.webkitExitFullscreen(); } }
HTML程式碼
1 <iframe id="iframe" src="" allowfullscreen="true"></iframe>
加上allowfullscreen 屬性就能使用全屏了