Jump to content

How to Check If JavaScript is Diabled?


chaseman

Recommended Posts

That is quite complex, is there no easier way, I actually wanted to use it for a Wordpress theme, to degrade a jQuery navigation bar to a CSS navigation bar. Depending on if JS is enabled or not it will use the corresponding css file.

Link to comment
Share on other sites

  • 1 month later...

I found this priceless piece of code. It detects whether javascript is disabled in your browser, and if so it can refresh to or redirect to an alternate javascript-safe page. This is great because now you don't have to worry about using javascript or how you code it, as long as you are willing to create an alternate page for that 3-5% user population that may have javascript disabled (our using a browser that does not support it).

 

You must place the script in between the <head></head> tags of your page. Here's the code:

 

<head>

<!--Re-Direct if javascript is disabled on browser-->

<noscript>

<meta http-equiv="refresh" content="6; URL= myalternatepage.php"><!--THIS IS ALL YOU NEED-->

<center><p><table cellpadding="0" cellspacing="0" border="0" width="550" class="redirect">

<tr><td width="100%" valign="top" class="redirect"><p>Your browser does not support JavaScript or you have javascript disabled.</td></tr>
<tr><td width="100%" valign="top">You must re-enable JavaScript for a richer experience of this site</td></tr>
<tr><td width="100%" valign="top"><b><p>You will be redirected to a javascript-safe website in about 5 SECONDS!</b></td></tr>
<tr><td><a href="http://www.plus2net.com/javascript_tutorial/enable_javascript.php" target="_blank"><p>Learn how to enable javascript</a></td>

</table>

</noscript>

<!--END Re-Direct if javascript IS DISABLED-->
</head>

 

It all happens in a single line of code, enclosed by the <noscript>tag:

 

<noscript> <meta http-equiv="refresh" content="6; URL= myalternatepage.php"> </noscript>

 

Then you can add any html valid code to let the users know of what's happening (This is optional). Also, you can change the refresh time you want the message to be displayed before it jumps to the new no javascript page.

 

This No Script code will alert visitors about being redirected to a new page.

This comes in especially handy for web designers and developers using javascript/jQuery/AJAX. So now your site can be as  dynamic and sleek as you want it to be.

 

Good Luck!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.