Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meta tag and javascript browser redirection - which has priority?

I'm developing in PHP, using Curl to follow links to their final destination. I occasionally reach a page with a meta tag redirection or a javascript redirection, and want to be smart enough to follow them. If a page has both, which should I follow (i.e., which would fire first)?

Sample meta tag refresh:

<meta http-equiv="refresh" content="0;URL='http://location1.com/'">

Sample javascript refresh:

<script>
window.location.href='http://location2.com/';
</script>
like image 396
Michael B Avatar asked Dec 16 '22 11:12

Michael B


2 Answers

Just created this file ( let's call it test.html )

<html>
  <head>
    <meta http-equiv="refresh" content="0;URL='http://location1.com/'">
    <script type="text/javascript">
      window.location.href='http://location2.com/';
    </script>
  </head>
  <body>
    Hello
  </body>
</html>

You can copy and save it. Once you open it, you'll be directed to http://location2.com

Do note that if the <script> tag is not in the <head> tag, the <meta> tag gets executed first.

like image 61
Nick Andriopoulos Avatar answered Apr 06 '23 01:04

Nick Andriopoulos


Hexblot's answer is a good idea -- just try it out if you want to see what happens. However, when I did try it out, Chrome went to location2, and IE went to location1. So it seems to be implementation dependent. You might want to have this be a configurable option on your script. In practice, though, any site that has one redirect in a meta tag and a different one in a script, is (a) unlikely, and (b) not coded very well, as they have no idea where you'll end up.

like image 42
Ryan M Avatar answered Apr 06 '23 01:04

Ryan M