15

I'm looking for a solution to show the visitor of my website an info message, if he has no javascript enabled. I tried it with a message in a div, that is visible by default but immediately hidden by a jQuery function on start up. The problem is, that the message is visible for a short time (until it is hidden), what is very irritating.

Are there other ways to show a message, if JS is not enabled?

Thanks, Konrad

4 Answers 4

43

Use the noscript tag:

<noscript>

  <div class="awesome-fancy-styling">
    This site requires JavaScript. I will only be visible if you have it disabled.
  </div>
  ...
</noscript>

See https://developer.mozilla.org/en/HTML/Element/noscript.

Sign up to request clarification or add additional context in comments.

2 Comments

There should be a category for "gimme" questions… oh, I guess [Duplicate]. ;-)
Given the use of browser extensions such as NoScript which selectively block JS without disabling it in the browser, the use of the <noscript> element isn't very effective.
5

You can use noscript, inside these tags is what will display if the user has javascript disabled.

If you want to hide the other content if the user doesn't have javascript enabled, you can do something like so (this uses jquery):

<style type="text/css">
    .example {
        display: none;
    }
</style>

<script type="text/javascript">
    $(document).ready(function(){
        $('.example').show();
    });
</script>

<div class="example">
    <p>...</p>
</div>

<noscript>
    <p>You must have javascript enabled for the example div to show!</p>
</noscript>

This will only show the content if the user has javascript enabled.

1 Comment

This is the most usefull answer because sometimes you want just to hide content of webtemplates providing alternatives for no-javascript (so instead of a overlay image with the "x" button, with no javascript you just open a new page with URL)
2

There is never a need to use <noscript> tags with browsers more recent than IE4 and Netscape 4. All that is needed is to use JavaScript to hide anything in the page that you don’t want those with javaScript enabled to see. This is way more flexible than <noscript> since you can actually test for the browser supporting specific JavaScript commands using feature sensing and only hide the HTML when the features that your JavaScript requires to work are actually supported properly by the browser.

<p align=center id=js_disabled_message>
    x.com requires JavaScript Enabled <br> <a href="https://www.enable-javascript.com/">www.enable-javascript.com</a>
</p>
<script>
    document.getElementById('js_disabled_message').style.display = 'none';
</script>

The above code will hide the p tag, only if js is enabled.
It's kinda of the opossite logic to detect if JavaScript is enabled and it works well on all browsers.

SRC

Comments

0

You can use '' and provide the error message you want.

    <html>
    <body>

    <script language="javascript" type="text/javascript">
    <!--
        document.write("Hello World!")
     //-->
    </script>

    <noscript>
     Sorry...JavaScript is needed to go ahead.
    </noscript>

    </body>
    </html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.