我正在尝试创建一个在线考试门户,在考试窗口中,我希望我的用户强制进入全屏,在考试完成之前不要离开它。我在这里使用了全屏API来实现全屏。
goFullScreen = () => {
if(document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen(); // W3C spec
}
else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen(); // Firefox
}
else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(); // Safari
}
else if(document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen(); // IE/Edge
}
}
我基本上已经复制了W3schools的代码。我想知道如何防止他们离开全屏?我可以在"Esc"键上返回false,但还有其他方法。此外,我不希望他们打开开发者窗口(即控制台(。我应该采用什么方法??
附言:如果重要的话,我正在使用React。
在制作电子应用程序或访问他们的计算机之前,无法阻止从全屏退出。
您想要做的事情是违背用户隐私的。您可以捕获esc
键,但不能覆盖浏览器。您可以做一件事,抓住esc
键,如果按下esc
键,则结束测试。
(我用的是JQuery,你也可以用香草JS(
if(document.fullscreenEnabled) {
// browser is almost certainly fullscreen
//Execute end test code here
}
如果此答案有帮助,请请求接受。。。