How to detect if JavaScript is disabled?

Ask a question

Does anyone know of some simple ways to detect if JavaScript is disabled? My intention is to give a warning that the site is not able to function properly without the browser having JS enabled.
Eventually I would want to redirect them to content that is able to work in the absence of JS, but I need this detection as a placeholder to start.

Coin iconoffer bounty
add comment

4 Answers


As I understood you’re trying to decide whether or not to deliver JavaScript-enhanced content. The best implementations degrade cleanly, so that the site still operates without JavaScript. I also assume that you mean server-side detection, rather than using the < noscript > element for an unexplained reason.
There is not a good way to perform server-side JavaScript detection. As an alternative it is possible to set a cookie using JavaScript, and then test for that cookie using server-side scripting upon subsequent page views. However this would not be suitable for deciding what content to deliver as it would not be able to distinguish visitors without the cookie from new visitors or visitors who are blocking cookies.

add comment

This is what worked for me: it redirects a visitor if javascript is disabled

<noscript><meta http-equiv="refresh" content="0; url=whatyouwant.html" /></noscript>
add comment

There is a special tag noscript for this purpolse

<noscript>Your browser does not support JavaScript!</noscript>
add comment

To detect if JavaScript is disabled in a web browser, use the <noscript> tag. The HTML <noscript> tag is used to handle the browsers, which do recognize <script> </script>script> tag but do not support scripting. This tag is used to display an alternate text message.

    <style type="text/css">
        .pagecontainer {display:none;}
    <div class="noscriptmsg">
    You don't have javascript enabled.  Good luck with that.
add comment

Your Answer