Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML <noscript> tag does not work

Tags:

html

Per definition <noscript> should show the text inside it if Javascript is disabled.

I used IE11 and disabled JavaScript to only see a blank page come up with no message at all.

<head>
<noscript>Javascript is disabled!</noscript>
<script>document.getElementById("demo").innerHTML="Script Enabled";</script>    
</head>
<p id="demo"> Test</p> 

Am I missing something?

like image 731
S Nash Avatar asked Dec 06 '25 15:12

S Nash


2 Answers

From what you have told us above, it seems as if you have entered/used the correct syntax.

I tried it in Chrome 47 and works fine, maybe try it in different browsers and see your results OR make sure you have actually turned off JavaScript.

Example:

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

From W3Schools - here

You could always do this too:

$(document).ready(function() {
  $('#noscript-description').css({
    'display' : 'none'
    
    // Just change the none to block to see the results
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
  <body>
    <p id="noscript-description">This can be seen if you <b>DO NOT</b> have JavaScript enabled.</p>
    <!-- I have added in jQuery, if you never realised -->
  </body>
</html>
like image 58
Josh Murray Avatar answered Dec 12 '25 09:12

Josh Murray


Your page works for me if javascript is disabled: It prints the "javascript is disabled" message at the top.

But if I enabled it, does not change the "Test" text, because the script is executed before the page is loaded. And even if it was loaded, there is no <body>, so document.getElementById will return null.

A working correction could be this:

<!doctype html>
<html>
<head>
<noscript>Javascript is disabled!</noscript>
<script>window.onload=function(){document.getElementById("demo").innerHTML="Script Enabled";}</script>
</head>
<body>
<p id="demo"> Test</p> 
</body>
</html>
like image 29
Little Santi Avatar answered Dec 12 '25 10:12

Little Santi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!