0

I have below code.But this keeps on reloading the page instead of redirecting.

    <script>
function my()
        {
          document.write("<meta content='0;url=http://google.com' http-equiv='refresh'></meta>");
        }
      </script>
      <center> <input name='image' onclick='my();' src='http://i.imgur.com/jgI5Ryt.png' type='image'/></center>

Note : i need meta refresh for some reason.So please help me with above code only.

  • 1
    rather than adding the meta tag just do `window.location = "http://google.com";` – Ronnie Jun 06 '13 at 20:07
  • 1
    you need meta refresh for some reason? What is the reason? – Ronnie Jun 06 '13 at 20:10
  • 2
    refresh is for **refresh**ing, keep it that way. Back in the time we had a language tag too that has been deprecated because of being misused. – Sebas Jun 06 '13 at 20:12
  • The reason is , when i use the link http://t.co/Eq01WkzCRg?paramater in window.location i am not getting referral url as t.co..... – user2461196 Jun 06 '13 at 20:15
  • You probably aren't getting a referral URL because you are testing locally. Throw it up on a server or localhost and try...`window.location` works fine and is the correct way to redirect. – Ronnie Jun 06 '13 at 20:20
  • "Setting window.location is not the same as following a link on that page. It starts a new request for the page as thought [sic] the user typed the URL into the browser's address bar." Interesting information about redirecting and referrer url: http://stackoverflow.com/questions/4762254/javascript-window-location-does-not-set-referer-in-the-request-header – showdev Jun 06 '13 at 20:22
  • nope...t.co sends the previous url as referral...but i want t.co itself as referral – user2461196 Jun 06 '13 at 20:24

1 Answers1

0

You can achieve it by replacing

document.write("<meta content='0;url=http://google.com' http-equiv='refresh'></meta>");

with

$('head').append('<meta content='0;url=http://google.com' http-equiv='refresh'></meta>');

ram2013
  • 505
  • 2
  • 9
  • 19
  • Meta redirects appear to be depreciated: "...users should not redirect users with this markup since [it] is non-standard, it disorients users, and it can disrupt a browser's history of visited pages." http://www.w3.org/TR/WCAG10-HTML-TECHS/#meta-element – showdev Jun 06 '13 at 20:31