Detecting if javascript is turned off

Hi,

could someone help me in figuring out how to detect if javascript is turned off.

Im guessing one could do it with javascript because javascript is a client-side language, but if the javascript is turned off wont it never be executed to check if the javascript is turned off?

Hopefully, someone can help me with this perplexing problem. And i know that one should not design their site necessarily based on js and i have the content and structure if js is off, but i just want to make sure so that everything that can be displayed with the js is displayed if js in on.

I hope i didn’t confuse anybody. And please reply with any questions, comments, concerns, or solutions :slight_smile:

Thanks in advance and Regards,
Team 1504

The <noscript> tag basically became unnecessary about 6 years ago. Since then it has required less code to omit those tags and use JavaScript to hide the content if JavaScript is enabled. This also has the benefit that you can hide inline content whereas the noscript tag is a block level tag. It also has the benefit that you can test if specific JavaScript commands are supported rather than just whether JavaScript itself is available and so still present the static content to those who have a browser that doesn’t have a sufficiently up to date version of JavaScript for your script to work.

My earlier example in this thread showed using JavaScript to hide one word if JavaScript is enabled. The code to do the same thing using the noscript tag involves about twice as much code.

The one exception to noscript being useless would be wrapping it around some CSS in the head of the page. You can’t do that with HTML 4 since noscript is currently only valid in the body. HTML 5 has expansded the use of noscript to allow it in the head and will presumably disallow its use in the body as a future amendment to the draft.

Thanks for all the help. I am going to do some research in the noscript tags?

I know this isnt the html forums but
Do u guys have any advice to go along with using them?

Or are there any noteable html5 changes in noscript tag?

Thanks for all your help and Regards,
Team 1504 :slight_smile:

A simple example of using JavaScript itself to detect if it is or isn’t enabled:

<p>JavaScript is <b id="script">not </b>supported.<p>
<script type="text/javascript">
document.getElementById('script').style.display = 'none';
</script>

If JavaScript is turned off then the word “not” appears in that paragraph. If it is enabled then that word doesn’t appear.

69+ downloads doesn’t mean 69+ computers with noScript installed. I bet half of downoad ar just for testing this addon or same user downloaded twice and so on… noScript doesn’t mean js turned off.

Except for the 69+ million people using Firefox and NoScript.

And that is just considering ONE scenario. :wink:

Agree with JesseDPate. Anyway, you always shoud provide a fallback scenario in case js is turn off. But this is not a major problem. Few peoples have js off.

If JS is on, then the JS will run. If JS is off, then it will not run. The only thing you can do for people without JS on is add a few <noscript> tags with alternate content.

Just remember that <noscript> is only valid in the <head> with HTML 5. In HTML 4 it is only allowed in the <body> (where it is useless).

The best place to put script tags is immediately before the </body> tag where they will not slow the loading of the rest of the page.

i just realised something…

My script does not work in IE because it uses css3 so is there a way that one could disable js if the browser is detected as IE using code?

Thank you guys for your help.

As i might have mentioned before, i made a carosel for my site so that the intro, 360 view, and some pictures are rotated as content for the home.
with your help and without using the <noscript> tag, I reconfigered the js so that no matter when javascript is disabled, be it before or while the carosel is running, then it will display the first slide which is the introduction and does not need javascript to run.
In other words.
Slide 1: no js needed
if js is disabled then everything past this does not happen.
transition:js needed
Slide 2:js needed
transition:js needed
Slide 3: no js needed and is not essential content.

Regarding what felgall said here:

HTML 4 since noscript is currently only valid in the body. HTML 5 has expansded the use of noscript to allow it in the head

Then the way to make your document html5 is by changing the doctype correct?

Also, I agree i have not seen noscript is a a while, that is why i forgot about it, but I swear i have seen it in html4 documents. Anyway, I too concur that it should only be used in the head where all <script> and <link< tags ought to be.

Thanks for all your help, again!

Regards,
Team 1504

P.S. for anyone reading this thread: I found this useful regarding the noscript tag

Statistics show that anything between 5-10% of all Internet usage involves a user or browser or device which has scripting either unavailable or disabled. As for NoScript, it DOES mean JavaScript is turned off, that’s the whole point of the extension… to cripple scripting unless specified as an exception. :slight_smile:

There’s Conditional Compilation, it would work for Internet Explorer only (so if their using IE, the script won’t do anything - kinda like conditional comments), but it won’t work for other browsers, and you REALLY don’t want to go down the road of having browser specific JavaScript (it’s the pinnacle of unprofessional). :slight_smile:

http://www.javascriptkit.com/javatutors/conditionalcompile.shtml