Treehouse: Grow your CSS skills. Land your dream job.

Last updated on:

Detect Javascript On/Off, With Notification

<script type="text/javascript">
   document.write("Welcome, you have Javascript on.")
</script>

<noscript>JavaScript is off. Please enable to view full site.</noscript>

If JavaScript is on the user gets a welcome message. If off, the user is instructed to turn it on.

Comments

  1. Toni Podmanicki
    Permalink to comment#

    You could also simply add a link with instructions on how to turn on JavaScript in the noscript tag.


    <noscript>For full functionality of this page it is necessary to enable JavaScript. Here are the <a href="http://www.enable-javascript.com" target="_blank"> instructions how to enable JavaScript in your web browser</a></noscript>

  2. Mani
    Permalink to comment#

    @Toni Podmanicki Thanks for the useful link

  3. amit mojumder

    Nice snippet. Thanks for sharing.
    But, isnt it supposed to show the notification on a pop up instead of site upper header?

    Thanks

    • Domenic
      Permalink to comment#

      That would require Javascript, which if the reader has it disabled then you can’t give an alert like that.

  4. Sherton
    Permalink to comment#

    I think it’s better in this way. An in-page message could be less annoying than a popup.

  5. Luanne
    Permalink to comment#

    Thank you for this very useful snippet. :)

  6. Prestashoop Indonesia

    Thanks for this one. Love this snippet

  7. LS76
    Permalink to comment#

    It doesn’t work if your site is at jimdo.de.

    My script for my site:

    document.getElementById(“JavaS”).innerHTML = “Welcome, you have Javascript on.”;

    For full functionality of this page it is necessary to enable JavaScript. Here are the instructions how to enable JavaScript in your web browser.

  8. Steven
    Permalink to comment#

    Great job.. Thanks alot. -Steven

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

```
<script>
  function example() {
    element.innerHTML = "<div>code</div>";
  }
</script>
```