微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何阻止网页在 React 中全屏显示?

如何解决如何阻止网页在 React 中全屏显示?

我正在尝试创建一个在线考试门户,在考试窗口中,我希望我的用户强制进入全屏模式,并且在考试完成之前不要退出。 我在这里使用了 Fullscreen 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' Keypress 上返回 false,但还有其他方法。另外我不希望他们打开开发人员窗口(即控制台)。 我应该采用什么方法??

附言如果重要的话,我正在使用 React。

解决方法

无法阻止退出全屏,除非您制作了一个电子应用程序或您可以访问他们的计算机。

您想要做的是侵犯用户隐私。您可以抓住 esc 键,但您无法覆盖浏览器。您可以做一件事,抓住 esc 键并在按下 esc 键时结束测试

(我用的是 JQuery,你也可以用 vanilla JS)

if(document.fullscreenEnabled) {
    // browser is almost certainly fullscreen
    //Execute end test code here
}

如果此答案有帮助,请请求接受...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。