Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibrarySecurity and Blocking

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

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.

(Misuse generally is with third-party cookies, but some people turn all cookies off. Let me also note in this aside that there are some legitimate reasons for using third-party cookies. They can generally be made into first-party cookies with similar functionality when avoiding third-party is essential. However, such techniques are beyond the scope of this article.)

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

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC