<noscript> No Script Element - (X)HTML Element Reference :: webDev

HTML Tag: <noscript>

Defines content to be used when a <script> can not be used (either because a browser does not support it or a user has switched off that functionality).

>noscript<

The <noscript> element has but one purpose: to provide content for people accessing the web page with a browser that either doesn’t support client-side scripting, or that has had its <script> support disabled by the user, perhaps for security reasons. Inside <noscript> you can use the same HTML elements that you’d include the <body> element; for example, <h1>, <p>, and other elements which are appropriate to the <!DOCTYPE> that you specify. However, you can’t use <noscript> inside the <head> to provide alternatives for JavaScript functions, as that would involve writing content inside the <head> element.

Note that it’s not just humans who might benefit from <noscript> content. If you have a web page that uses client-side scripting to create navigation, for example, those links will be all but hidden from search engines, which won’t parse the scripts contained in the <script> element. A simplified navigation block within the <noscript> element can provide a route for search engines to follow when they’re indexing your site, regardless of whether the users ever see that content.

There’s one gray area that you should be aware of. The content inside the <noscript> will only appear if <script>s aren’t supported, or are disabled in the user’s browser. There are scenarios in which a <script> won’t be actioned—for example, when security settings on a firewall detect potentially malicious code in an external <script> file, and block the scripts. This kind of situation may cause a page to render improperly, but <noscript> won’t be shown, because in this case <script>s are supported, it’s just that some have been blocked.

The solution? Don’t rely on <noscript> completely. It may be better simply to create a message on the page in clear text—for example, in a <div> with an id="" (to uniquely identify the element). Then, use the <script>ing capability to check that the <noscript>’s functions, variables, and objects have been successfully loaded and work properly. If all the conditions are met, use <script>ing to retrospectively remove or update the content of that message. If the part of the <script> that performs the magic fails to make it through the firewall, so will the ability to remove that warning message.

This example shows a typical application of <noscript>:


      						<noscript>
      							<h1>Houston, we have a problem</h1>
							<p>It appears that your web browser does not support JavaScript,
								or you have temporarily disabled scripting. Either way, this site
								won't work without it. Please take a look at our
								<a href="/support/browsers/">browser support page</a> for more help.
      						</noscript>
					

The <noscript> element is used to provide a warning message that <script>s aren’t supported or have been disabled, to provide a pointer to show users how they can resolve the problem, or alternatively, to provide a simplified version of the content that would have appeared if <script>ing were enabled (although that approach brings with it the issue of maintaining two versions of your markup).

The noscript tag

The <noscript> tag can be used define an area which will only be displayed when the script cannot be run. This can happen when the browser does not recognize the scripting language or when scripting is disabled in the browser. Some users disable the javascript option in the IE and in that case you could show a message in the <noscript> tag.

<noscript> No Script Element - (X)HTML Element Reference :: webDev