Requiring Browsers to Run JavaScript
Some web pages require JavaScript. Without JavaScript, they don't work right.
Shopping carts are an example, to keep track of items selected and to launch overlays with information.
Other examples:
-
Sites that offer custom visual formatting, like preferred colors and font sizes, require JavaScript to implement the preferences.
-
When a form is abandoned, JavaScript is required to automatically refill fields with previous data when the person returns to the page.
-
Member sites are likely to require JavaScript to recognize the login cookie.
JavaScript has been misused so much, especially when related to cookies, that some people are turning JavaScript off via their browser preferences.
Yet, just because JavaScript can be misused doesn't change the situations where it is required.
If you have any web pages that must not be viewed unless JavaScript is available, this article contains the means to make it so.
The technique for requiring browsers to run JavaScript before they can access a page is simple:
→ Use the HTML noscript
tag to redirect JavaScript-disabled browsers to a different web page.
Then, browsers that display the web page where JavaScript is required is indeed JavaScript-enabled.
Here is the noscript
tag with a meta http-equiv="refresh"…
tag to force a redirect.
<noscript>
<meta http-equiv="refresh" content="0; url=>http://example.com/">
</noscript>
Replace http://example.com/
with the URL of the alternative web page for JavaScript-disabled browsers. The meta
tag redirects them to the specified URL.
Because the redirect command is between noscript
tags, it will affect only JavaScript-disabled browsers. JavaScript-enabled browsers will not be subject to that meta
tag.
Put the noscript
tag high in the head
area of the web page. The reason for the high placement is so any browsers that will be affected by it can do the redirect before wasting time processing code extraneous to them.
This article first appeared with an issue of the Possibilities newsletter.
Will Bontrager