本代碼針對 IE 4+ 與 Netscape 4+ 時代設計,利用 window.open() 的 fullscreen=yes (IE 專屬) 與 window.resizeTo()/moveTo() 模擬全螢幕效果。現代瀏覽器嚴格限制全螢幕 API 僅限用戶手勢觸發 (requestFullscreen()),且彈窗攔截器會阻擋非用戶主動點擊的 window.open()。此方案僅供歷史參考,不可用於現代生產環境。
<script language="javascript">
function intro() {
// Mac IE 4 特殊處理
if (navigator.appVersion.indexOf("Mac") != -1 &&
navigator.userAgent.indexOf("MSIE") != -1 &&
parseInt(navigator.appVersion) == 4) {
skip();
} else {
popup();
}
}
function skip() {
location.href = "https://yourdomain/index.htm";
}
function popup() {
var version = parseFloat(navigator.appVersion.substring(
navigator.appVersion.indexOf('.') - 1, navigator.appVersion.length));
if (version >= 4) {
if (navigator.appName == "Netscape") {
// Netscape: 無 fullscreen 參數,僅開大視窗
var win = window.open("https://yourdomain/index.htm", "Hello", "scrollbars");
win.focus();
} else if (navigator.appName == "Microsoft Internet Explorer") {
// IE: 使用 fullscreen=yes
window.open("https://yourdomain/index.htm", "screen", "fullscreen=yes");
}
} else {
// 低版本瀏覽器直接跳轉
location.href = "https://yourdomain/index.htm";
}
}
</script>
<BODY onload="intro()"></BODY>
navigator.appName:"Microsoft Internet Explorer" / "Netscape"navigator.appVersion 解析主版本號| 瀏覽器 | window.open 特徵參數 | 備註 |
|---|---|---|
| IE 4+ | fullscreen=yes | 真正全螢幕模式 (kiosk 模式) |
| Netscape 4+ | scrollbars + resizeTo/moveTo | 模擬最大化,非真全螢幕 |
"https://
yourdomaintg/index.htm" 換行導致 URL 失效ypurdomain、npgae、ppgaeonload 觸發的彈窗<button id="fsBtn">進入全螢幕</button>
<script>
document.getElementById('fsBtn').addEventListener('click', () => {
const elem = document.documentElement;
if (elem.requestFullscreen) elem.requestFullscreen();
else if (elem.webkitRequestFullscreen) elem.webkitRequestFullscreen(); // Safari
else if (elem.msRequestFullscreen) elem.msRequestFullscreen(); // IE11
});
</script>
// 僅在用戶點擊事件中調用
const win = window.open(url, '_blank', 'noopener,noreferrer');
if (win) {
win.moveTo(0, 0);
win.resizeTo(screen.availWidth, screen.availHeight);
}
.fullscreen-container {
position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
z-index: 9999; background: white; overflow: auto;
}
早期「全螢幕視窗」屬於侵入式設計,現代 Web 標準賦予用戶完全控制權。開發者應改用 Fullscreen API 搭配用戶交互,或以 CSS 實現沉浸式體驗,尊重用戶瀏覽自主權。