Redirect from an HTML page without using JavaScript

Matthew C.

The Problem

You have a webpage that relies on JavaScript for functionality but you may have users that have JavaScript disabled in their browser. You want to redirect these users to a page that does not rely on JavaScript. How do you do this without using JavaScript?

The Solution

You can add a noscript HTML element in the head element of your HTML, above any script tags. If JavaScript is disabled, the HTML between the noscript tags will be inserted into the page.

In the following example, if a user has disabled JavaScript, the contents of the page will be hidden using CSS and the user will be redirected to another URL using the meta HTML element:

Click to Copy
<noscript> <style> html { display: none; } </style> <meta http-equiv="refresh" content="0; url=https://www.bing.com/" /> </noscript>

Here, the meta element contains an HTTP-equivalent directive to “refresh” the page and the content attribute specifies the number of seconds until the page is reloaded. If the content attribute includes a valid url, the user will be redirected to it.

You can also use a noscript tag in the HTML body to show a message to the user if they have JavaScript disabled:

Click to Copy
<noscript> <p> This site is best viewed with Javascript. If you are unable to turn on Javascript, please use <a href="https://www.example.com/your-no-js-page">this site</a>. </p> </noscript>

Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

Share on Twitter
Bookmark this page
Ask a questionJoin the discussion

Related Answers

A better experience for your users. An easier life for your developers.

    TwitterGitHubDribbbleLinkedinDiscord
© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.