Home » Php » php – <noscript> redirection

php – <noscript> redirection

Posted by: admin July 12, 2020 Leave a comment


I want to redirect the user to a certain page if he/she has javascript disabled. I tried this code:

<noscript><?php url::redirect('controller/method'); ?></noscript>
// url::redirect is much like the location header

to no avail…

How do I do this?

How to&Answers:

You can’t use meta refresh tag then remove it using Javascript because the browser is set to redirect upon reading the meta refresh tag and it’s too late for JS to manipulate it.

The only way is to either do what Daniel suggested, or to show up a link when there’s no Javascript:

<a href="">Click here to continue</a>

Or you can try to fail gracefully: Do you plan for javascript being off?


Since the headers have already been sent, you’ll need to use standard HTML markup:

  <meta http-equiv="refresh" content="0;url=noscript.html">

Trying this on both Firefox and IE seems to work well… With JavaScript enabled, the <meta> tag is ignored. When it is disabled, the browser redirects to noscript.html.


There is no way to do a redirect based on if javascript is disabled. Why not do the opposite – redirect if javascript is enabled?

   window.location = "...";


Add this as the first element in your body, style it to suit, and perhaps offer a link inside of it to a noscript page:

<div onload="return false;">
    <!-- PAGE CONTENTS -->

I use a more verbose method of this (that basically makes it appear as a modal dialog and all pretty) on pages where a client does not allow me to use more compatable means. I’ve tested in IE6+ and all other major browsers with great success.