Rajesh Omanakuttan
Rajesh Omanakuttan

Reputation: 6918

Stop loading the page if Javascript is disabled

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?

Thanks :)-

Upvotes: 2

Views: 2288

Answers (1)

elclanrs
elclanrs

Reputation: 94121

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">

In CSS:

body.no-js { display: none; }

Then in JS:

document.body.className = "";

Upvotes: 6

Related Questions