How to know and handle disabled javascript in browser

In this blog, I’ve been writing a lot of tips and tutorials using JavaScript. I really love JavaScript and hope that you guyz also like it. But what to do when JavaScript is disabled in the client’s browser?. I would like to redirect the visitor to a warning page where he’ll be suggested to enable the JavaScript.

In many scenario, we must need JavaScript in some pages and we never want to process that page.In this post, I’ll show you how to know and handle the disabled JavaScript in browser.

First click on the below link to see a JavaScript enabled page. Now, disable the javaScript in browser and click the below link.

View the Demo

How to know JavaScript is disabled in browser?

As you guyz know, <script></script> tag is used for javaScript. Same way there is <noscript></noscript> tag which gets in action when the Javascript is diabled in browser.

<script>code here gets executed when javascript is enabled</script>
<noscript>code here gets executed when javascript is diabled</noscript>

How to handle diabled javascript in browser?

When javascript is diabled I always want user to be redirected to a page to show warning to enabled javascript.But, JavaScript is diabled how to do this ? well there is meta tag in HTML named “meta refresh” which will redirect you to another page in the interval specified in that header

  <META HTTP-EQUIV="Refresh" CONTENT="0;URL=disabled.html">

As, you can see above code inside noscript, there is “meta refresh” tag with intevel of “0” second. As, the javascipt is disabled in that page, the browser gets redirected to “disabled.html” to show some warning message

Download Example Files

16 thoughts on “How to know and handle disabled javascript in browser

  1. Jason

    There is no good reason today to use the noscript tag. It may take a bit more thought up front but it is much better to use unobtrusive JavaScript techniques. For example, you can create a simple message in a unique tag (such as p) at the beginning of your markup indicating that JavaScript is required to get full use of your site/application. Then, all you need to do is $(“#uniqueId”).hide() the element using JavaScript, and you avoid the need for a redirect or other harsh punishment for disabling scripting.

  2. are right and it would be better not to give punishment..but If you’ve a highly rich javascript application then you really don’t want to use the website to be browsed with disabled javascript…but If the page don’t have rich user interface then your solution is highly accepted..

  3. I see both your points but I do believe what Roshan is saying, if your application rich enough there is no reason to keep them on that page.

    Redirect them to a page letting them know your page is safe and let them know the benefits of enabling JavaScript.

  4. what ashley said. javascript-intensive pages should redirect to a separate page for site visitors with javascript disabled. it doesn’t make sense to extensively code an application to allow visitors with javascript disabled to view the site when the majority of the intended functionality is disabled. wouldn’t viewing a disabled site (without being redirected) be a punishment in itself? what jason said — unobtrusively hiding page elements rather than redirecting visitors — would make more sense when applied to less javascript-heavy sites.

  5. by the way, noscript tag is not allowed in head tags. so if you are addicted to w3c standards and green html tidy tick in firefox, this usage would be problematic.

  6. Ya Neru right…if you want your page to be validated from w3c please don’t use noscript tag inside head tag…

  7. another addition :)
    being curious, i just disabled javascripts and tried some websites like google reader, team vidget, etc, there are 3 different solutions for these javascript disabled browsers,
    1) use roshan’s solutions and redirect another page.
    2) use jason’s suggestion and display a “javascript should be enabled” message
    3) given up some navigation and content display effects and making site usable both javascript enabled and disabled cases.

  8. Ticonetster

    Yeah I use the noscript option to give some kind of message but i didn’t know that you can use those meta tags like that. Sweet! thanks man.

  9. Daniel

    So, i read all this for nothing, in the end this is not valid by W3C :(
    Don’t resolve a (@&#2**&@, sory but why in the first place, this fu99)ck brownsers has to allow users desable javascript? FUC…..CK! Sory i angry… another solution complacent with W3C?

    I dont want to do i site only for idiots who dont have js allowed!

  10. Nick

    Just another addition to this thread.

    Redirecting to another page is “cloacking” and will get your site banned by Google et al

    I have simply created 2 external css files, one called for js enabled browsers and one for those disabled. Yes that means 2 files, not one need to be maintained.

    I wanted to keep the features in my js requiring pages as I like them and for the minority of js disabled visitors the trade-off in restricted visual/functionality and file maintenance and impact is more than acceptable.

    I simply have an unthreatning tiny unobtrusive message saying enable js for a richer experience in the top right of my pages.


  11. sanker

    Thanks a lot for the idea.

  12. It is very cool. Thanks for the script.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>