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,

  1. <script language=”javascripttype=”text/javascript”>
  2. window.location.href=”login.jsp?backurl=”+window.location.href;
  3. </script>

2,

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

3,

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

4,

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

5,

  1. <script language=”javascript”>
  2. alert(Access Violation);
  3. top.location=”error.jsp”;
  4. </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
You can leave a response, or trackback from your own site.

10 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.

Leave a Reply