如果Javascript已停用,请停止加载页面 [英] Stop loading the page if Javascript is disabled
问题描述
我有一个Rails网络应用程序(在线考试系统)。我已禁用右键单击,选择,复制等使用JavaScript在考试界面。所以,我想让我的应用程序来检测是否启用JavaScript启动界面启动。我已通过使用< noscript>
标记检查它,如下所示。
I have a Rails web app (Online Examination System). I have disabled Right click, selection, copy etc using JavaScript in the examination interface. So, I want my app to detect whether JavaScript is enabled on interface start up. I have checked it by using <noscript>
tag as follows.
<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?
感谢:) -
推荐答案
$ c> no-js 在 body
元素上隐藏它,然后用JavaScript显示它,所以如果用户有JS禁用他们空白页面。
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 class="no-js">
在CSS中:
body.no-js { display: none; }
然后在JS中:
document.body.className = "";
这篇关于如果Javascript已停用,请停止加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!