我用一個函數在瀏覽器中使用javascript切換全屏模式。全屏禁用所有鍵盤按鍵
function toggleFullScreen(elem) {
// ## The below if statement seems to work better ## if ((document.fullScreenElement && document.fullScreenElement !== null) || (document.msfullscreenElement && document.msfullscreenElement !== null) || (!document.mozFullScreen && !document.webkitIsFullScreen)) {
if ((document.fullScreenElement !== undefined && document.fullScreenElement === null) || (document.msFullscreenElement !== undefined && document.msFullscreenElement === null) || (document.mozFullScreen !== undefined && !document.mozFullScreen) || (document.webkitIsFullScreen !== undefined && !document.webkitIsFullScreen)) {
if (elem.requestFullScreen) {
elem.requestFullScreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullScreen) {
elem.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
}
並且創建了一個函數來在全屏模式下禁用鍵盤按鍵。 大多數鍵都被禁用,但仍有一些鍵仍在工作(F11,ESC,ALT + Tab)。
function disable()
{
document.onkeydown = function (e)
{
return false;
}
}
反正還有禁用它們嗎?因爲我正在開發一個在線考試,該考試仍應全屏顯示,直到考試結束。
Alt-tab或CTRL-ALT-DELETE被操作系統接管,所以我懷疑是否有任何阻止這些操作的方法。 – apokryfos