No-Javascript Detection Script + Redirect

Gdoron mentioned noscript already. Together with meta refresh¹ you can redirect users if they have JavaScript disabled.

A JavaScript redirect can be done with location.replace(URL).

<head>
  <noscript>
    <meta http-equiv="refresh" content="0; url=http://example.com/without-js" />
  </noscript>

  <script>
    location.replace('http://example.com/with-js');
  </script>
</head>

Example of noscript+meta refresh: http://pastehtml.com/view/bsrxxl7cw.html

1) Mind the drawbacks section of the Wikipedia article!

Meta refresh tags have some drawbacks:

  • If a page redirects too quickly (less than 2-3 seconds), using the “Back” button on the next page may cause some browsers to move back to the redirecting page, whereupon the redirect will occur again. This is bad for usability, as this may cause a reader to be “stuck” on the last website.
  • A reader may or may not want to be redirected to a different page, which can lead to user dissatisfaction or raise concerns about security.

Leave a Comment