防止ESC退出全屏模式 [英] Prevent esc from exiting fullscreen mode
问题描述
我的网页使用以下代码转换为全屏模式.
var element = document.getElementById("b");
if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
我想通过单击esc来防止退出全屏模式
我尝试了以下代码,但无法正常工作.
document.onkeydown = function (evt) {
alert("1");
if (evt.keyCode == 27) evt.preventDefault();
}
如果我按Escape键,则它首先从全屏退出,然后从下一次按下,上述功能将起作用并提示"1".
我也尝试了以下代码,但没有任何好处
function keyUp(){
alert("sdd");
document.querySelector("#start").addEventListener("keydown",function(e){
var charCode = e.charCode || e.keyCode || e.which;
if (charCode == 27){
return false;
}
});
}
和
document.onkeydown = function (e) {
if(e.which == 27){
return false;
}
}
任何人都知道如何防止退出全屏模式.还是如何使用f11键以编程方式将网页转换为全屏模式?
任何符合标准的浏览器都不会(也不应该)阻止您这样做.完全是因为这样做会很麻烦并且会使用户感到困惑,他们希望始终有一个清晰的紧急按钮"来逃离屏幕.
以下是api规范:
Mozilla开发人员网络
W3C >
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?
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
这篇关于防止ESC退出全屏模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!