如果禁用了Javascript,则停止加载页面

Stop loading the page if Javascript is disabled

本文关键字:加载 Javascript 如果      更新时间:2023-09-26

我有一个Rails web应用程序(在线考试系统)。我在考试界面中禁用了使用JavaScript的右键,选择,复制等功能。我想让我的app检测JavaScript是否在界面启动时启用。我已经用<noscript>标签检查过了,如下所示

<noscript>
    <meta http-equiv="refresh" content="5">
            <div id="noscript_message" style="color: white; background-color: red;">
            It is detected that Javascript is turned off in your web brower. Please turn it on to load the page correctly. For more reference about how to turn it on, please refer <a href="http://www.enable-javascript.com/" target="_blank">
 instructions how to enable JavaScript in your web browser</a>.
            </div>
</noscript>

但是我只能检测并显示一条消息作为警告。我的意图是不加载该页面,只显示警告消息。如何实现这一目标?

谢谢:)-

你可以在你的body元素上使用no-js类,用CSS隐藏它,然后用JavaScript显示它,所以如果用户禁用了JS,他们会得到一个"空"页面。

<body class="no-js">
在CSS:

body.no-js { display: none; }

然后在JS中:

document.body.className = "";