2

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 :)-

2
  • 1
    <noscript><meta http-equiv="refresh" ...></noscript>, but it is damned ugly. You shouldn't disable right click, copy, etc... that is sooo old school... Commented Apr 4, 2013 at 9:28
  • Kindly mention the reason for down voting.. Commented Apr 4, 2013 at 9:30

1 Answer 1

6

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 = "";
Sign up to request clarification or add additional context in comments.

5 Comments

document.body... don't over complicate :)
<body> tag has already a class name assigned for with other specifications. Then?
You can use jQuery or replace it: document.body.className = document.body.className.replace('no-js','')
@elclanrs: Hey, How can I detect 'javascript is enabled' in javascript file? Inside that checking only, I can furnish the above statements
but anyone with even basic knowledge of html/css will change that display:none to display:block and bypass the check, no? Is there any way to REMOVE the content entirely

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.