Redirect users with JavaScript

 

In JavaScript, we have the possibility to redirect users from one page to another, just like if we made an HTTP redirect.

Actually there is two ways! (:

 

1.  Using the raplace

Window.location.replace(‘Your url’);

This method will just replace your document with another, using the same spot in our browsers history. So now the user won’t be able to return to the previous page again using the back button (:

This can be very handy after a login or a payment gateway!

 

2. You can also use the href method (Not like a HTTP redirect)

Window.location.href(‘Your url’)

This method will follow a url to a new page and leave a trace in the browsers history.

 

Below are some examples that use technique 1. To redirect a user

<input type="button" onclick="window.location.replace('Redirect.htm')" value="Try me" />
<div onclick="window.location.replace('Redirect.htm')">Redirect</div>
<a href="#" onclick="window.location.replace('Redirect.htm'); return false">Redirect</a>

 

 

I hope this guide was helpfull to you? (:

Remember to leave a comment bellow :D

c2ec4323-9a1b-4aa0-8d3e-4fb154664e7a.png
Category;Guides
Downloads;3
Hits;838
Size;15 kb.

Comments


Show mail in post?

Contact

Phone: +45 31 32 22 93
Email: psduck112@gmail.com
facebook: Jim Rasmussen

Info

Server host: Surftown.dk
Copyright ©: D-Zig.com 2009 - 2011