简体   繁体   English

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

[英]Stop loading the page if Javascript is disabled

I have a Rails web app (Online Examination System). 我有一个Rails网络应用程序(在线考试系统)。 I have disabled Right click, selection, copy etc using JavaScript in the examination interface. 我已在检查界面中使用JavaScript禁用了右键单击,选择,复制等功能。 So, I want my app to detect whether JavaScript is enabled on interface start up. 因此,我希望我的应用能够检测界面启动时是否启用了JavaScript。 I have checked it by using <noscript> tag as follows. 我已经通过使用<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>

But I could only detect and show up a message as warning. 但是我只能检测并显示一条消息作为警告。 My intention is not to load that page and show up the warning message only. 我的意图不是加载该页面并仅显示警告消息。 How that can be achieved? 如何实现?

Thanks :)- 谢谢 :)-

You could use no-js class on your body element and hide it with CSS, then show it with JavaScript so if users have JS disabled they get an "empty" page. 您可以在body元素上使用no-js类,然后用CSS将其隐藏,然后使用JavaScript进行显示,因此,如果用户禁用了JS,他们将获得一个“空”页面。

<body class="no-js">

In CSS: 在CSS中:

body.no-js { display: none; }

Then in JS: 然后在JS中:

document.body.className = "";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM