1. Technology

Reasons to Avoid Noscript

A Tag to Hide from Modern Browsers


The noscript tag used to be useful in Internet Explorer 4, Netscape 4 and earlier browsers but the introduction of IE5, Firefox, Opera, Safari, Chrome etc make this tag redundant. Here are several reasons why the noscript tag should be considered dead and buried.

  • The noscript tag only detects whether the browser has JavaScript enabled or not. If JavaScript is disabled in the Firewall rather than in the browser then the JavaScript will not run and the content of the noscript tag will not be displayed.
  • Many JavaScripts are dependent on a specific feature or features of the language being supported in order for them to be able to run (for example document.getElementById). Where the required features are not supported the JavaScript is unable to run but since JavaScript iteself is supported the noscript content will not be displayed.
  • The most useful place to use the noscript tag is in the head of the page where it would be able to selectively deternine what stylesheet and meta tags get applied to the page as the page is loading rather than having to wait until the page is loaded. Unfortunately the noscript tag is only valid within the body of the page and so cannot be used in the head.
  • The noscript tag is a block level element and therefore can only be used to display entire blocks of content when JavaScript is disabled. It cannot be used inline.
  • Ideally, web pages should use HTML for the content, CSS for the appearance, and JavaScript for the behaviour. Using the noscript tag is applying a behaviour from within the HTML rather than applying it from JavaScript.
The thing is that while noscript was a useful tag back when JavaScript was first introduced, there are more effective ways of changing the content that is displayed now that give far greater control. Instead of surrounding the content that is only to be displayed when JavaScript is disabled it is simply a matter of making sure that the tag that does surround the content has an id. The JavaScript itself can then set the display property for that id to none where the required JavaScript features are supported. This use of JavaScript to hide the content when the required JavaScript code is not supported resolves all of the above issues regarding the use of JavaScript.
  1. About.com
  2. Technology
  3. JavaScript
  4. Reference
  5. Reasons to Avoid Noscript and Use JavaScript Instead

©2014 About.com. All rights reserved.