0

When user login with Internet Explorer and user's javascript setting is disabled, I want to show an alert to user. I've tried to use <noscript> tags. I've changed my javascript settings (enabled to disabled) for test it but when I try it, nothing displays. How can I do it? Here are my codes below;

<script>
  document.write("Hello World!")
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>

<p>A browser without support for JavaScript will show the text inside the noscript element.</p>
Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
escada
  • 23
  • 1
  • 3
  • Possible duplicate of [Shouldn't we use – emerson.marini Feb 10 '15 at 15:20
  • You could have a hidden div tag with the message inside, if noscript then display the div tag to show the message? – NewToJS Feb 10 '15 at 15:20
  • @NewToJS: How would you plan on showing a hidden div if JS is disabled? – Cerbrus Feb 10 '15 at 15:23
  • @Cerbrus Sorry i mean have the div set to display, use JS to hide the div. – NewToJS Feb 10 '15 at 15:24
  • If you're really disabling JavaScript as you say, that should work. MelanciaUK's link is useful if you need to handle JavaScript disabled at a more fundamental level, but what you said you did in your question should be showing that `noscript` content. – T.J. Crowder Feb 10 '15 at 15:25
  • 1
    It works BUT you have to set `noscript` inside BODY or set the HEAD to `display: block;` (of course, don't!) – A. Wolff Feb 10 '15 at 15:25

1 Answers1

3

This is a nice one. It's because your example its so minimal. The browser automatically wraps the <script> and <noscript> tags in <head>, which means that while the JS executes and writes "Hello world", the <noscript> tag gets hidden, because it's in the <head>.

If you manually place them in the <body> it works fine:

<html><head></head>
<body>
<script>
  document.write("Hello World!")
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>

<p>A browser without support for JavaScript will show the text inside the noscript element.</p>
</body>
</html>
Scimonster
  • 32,893
  • 9
  • 77
  • 89
  • 2
    Fairly big assumption that the quoted HTML is **all** of the OP's HTML. But if you're right... :-) – T.J. Crowder Feb 10 '15 at 15:26
  • 1
    @Frank: That depends entirely on what you're doing with it. If you're trying to display content, then yeah. – T.J. Crowder Feb 10 '15 at 15:42
  • This is true, I just assumed that since the question was about displaying content, he'd probably want it to be in the body element. But you are right, it depends on your application. – Frank Feb 10 '15 at 15:50