Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

javascript - Prevent esc from exiting fullscreen mode

My webpage converted to full screen mode using this following code.

    var element = document.getElementById("b");


    if (element.mozRequestFullScreen) {

      element.mozRequestFullScreen();
    } else if (element.webkitRequestFullScreen) {

      element.webkitRequestFullScreen();
   }

I want to prevent exit from fullscreen mode by clicking esc

I tried this following codes but not working.

document.onkeydown = function (evt) {
            alert("1");
    if (evt.keyCode == 27) evt.preventDefault();
}

If i press escape it first exit from full screen and from next press the above function will work and alert "1".

I tried the following codes also but no benefit

  function keyUp(){
    alert("sdd");
document.querySelector("#start").addEventListener("keydown",function(e){
    var charCode = e.charCode || e.keyCode || e.which;
    if (charCode == 27){

        return false;
    }
});

}

and

document.onkeydown = function (e) {
        if(e.which == 27){
                return false;
        }
}

Anybody know how to prevent exiting from full screen mode. Or how to convert webpage to fullscreen mode using f11 key programatically?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Any browsers complying to the standards will not (and should not) let you block this. Quite simply because it would be very intrusive and will confuse the users, who expect to always have a clear "panic button" to escape a screen.

Here are the api specifications:
Mozilla Developer Network
W3C


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...