Search code examples
javascriptphphtmlmeta-tagsnoscript

Meta refresh tag not redirecting with noscript tags


I have a <noscript> tag with a meta refresh in it, but when I turn off the browsers javascript, it doesn’t redirect. Here is my code:

<noscript>
<meta http-equiv="refresh" content="0; url=http://mysite.tld/javascript-disabled.html" />
</noscript>

here is my code after the meta tag, and before it:

 <html>
 <head>
<noscript>
<meta http-equiv="refresh" content="0; url=http://mysite.tld/javascript-disabled.html" />
</noscript>
</html>
</head>

This is in a PHP file so I do have php script as follows, if that is interfering:

<?php
 echo "window.alert('test')";
?>

I cant use php header to redirect, like I know is possible, because headers are already called in header.php

I also tried:

<?php
 echo "<noscript>
<meta http-equiv="refresh" content="0; url=http://mysite.tld/javascript-disabled.html" />
</noscript>";
?>

But that causes a php error output.


Solution

  • The error cause by the quote. Try change it to:

    <?php
     echo "<noscript>
    <meta http-equiv='refresh' content='0; url=http://mysite.tld/javascript-disabled.html' />
    </noscript>";
    ?>
    

    But i'm dought if this will work.

    A diffrent approach will be to create a non-javascript page and use javascript to redirect. Something like:

    window.location.assign("jsenable.html")
    

    Good luck!