5 ways to redirect URL with Javascript

Flight-Tracker-48x48

How to do a Redirect to an HTTP POST Request with Javascript?I summarized 5 ways to redirect URL.(The purpose of below script is to perform a local redirect using Javascript)

1,

<script language=”javascript” type=”text/javascript”>
window.location.href=”login.jsp?backurl=”+window.location.href;
</script>

2,

<script language=”javascript”>
alert(”back”);
window.history.back(-1);
</script>

3,

<script language=”javascript”>
window.navigate(”top.jsp”);
</script>

4,

<script language=”JavaScript”>
self.location=”top.htm”;
</script>

5,

<script language=”javascript”>
alert(”Access Violation”);
top.location=”error.jsp”;
</script>
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

25 Responses to “5 ways to redirect URL with Javascript”

  1. Joules says:

    Just be aware of bug 223 in Internet Explorer 6 (and below)
    http://webbugtrack.blogspot.com/2007/09/bug-223-magical-http-get-requests-in.html

    You will find that in certain cases setting the .href from javascript will NOT work in IE.

  2. JANARTHANAN says:

    Please tell me redirection, if use redirection code
    It effect Google search engine ?

  3. Manuel says:

    It has helped me.
    Thanks a lot.

  4. atawai says:

    I using 1′st model. Its work, but I can not guarantee google will happy

  5. Arvin says:

    I’m using number 4.
    self.location=”top.htm”;
    Works in IE6 and FF3.
    Thanx for sharing.

  6. Mahesh says:

    this is good. thanks a lot.

  7. [...] 5 ways to redirect URL with Javascript [...]

  8. Raj says:

    I tried option 4 will implementing a solution for CSRF and it works
    in IE 7.0 , FF 3.5 and Opera 10.10

    Thanks
    Raj

  9. Rajbabu Gunaseelan says:

    Simple implementation of CSRF protection in JSPs:

    self.location=”Login.jsp”;

    self.location=”Login.jsp”;

  10. mindwork says:

    Thx a lot, It has helped me.

  11. Anderson says:

    very nice, didn’t know there were so many ways

  12. Abbas says:

    thanks ..useful info..easy to find ..came up at top in google search..

  13. Rajeev says:

    location.replace(‘/’);

    This is what I use, this will replace url in browser history, so browser back button wont result in a loop

  14. Rajeev says:

    [script language=”javascript”]
    location.replace(‘www.regexhacks.com/’);
    [/script]

    This is what I use, this will replace url in browser history, so browser back button wont result in a loop

  15. DavidM says:

    Good idea for a post. Very useful.

    @Rajeev
    Interesting. They need to add that one to the list.

  16. prithvi says:

    Thank you so much for the simple yet powerful way of navigation. It solved my purpose tentatively.

  17. Zbigniew says:

    Great helpfull collection, please also include that way

    cheers :)

  18. Zbigniew says:

    Great helpfull collection, please also include that way:

    //*sorry – no script in comments*//

    setTimeout(‘Redirect()’,3000);
    function Redirect()
    {
    location.href = ‘hxxp://forfruits.pl’;
    }
    //end//

    cheers :)

  19. Dinesh Kumar says:

    I don’t know which one to use for my website.

  20. Arnold says:

    hello thеre and thank уou for youг infoгmatіon –
    I’ve certainly picked up something new from right here. I did however expertise several technical issues using this website, as I experienced to reload the website many times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I am complaining, but slow loading instances times will often affect your placement in google and can damage your quality score if advertising and marketing with Adwords. Anyway I am adding this RSS to my email and could look out for much more of your respective fascinating content. Make sure you update this again very soon.

  21. al000y says:

    Thank you

  22. MMAIDOUDI says:

    Thanks for this information but I have a little question
    What’s the difference between these methods ???

  23. calam says:

    I found the codes i need. thanks for the post

Leave a Reply