Redirecting visitors with Javascript can be achieved by one of the methods given below.

location.href Method

Including the following script will immediately redirect visitors to the URL entered.

<script type="text/javascript">
     location.href='http://www.bloggingdeveloper.com';
</script>
 

location.replace Method

Including the following script will immediately redirect visitors to the URL entered.

<script type="text/javascript">
     location.replace('http://www.bloggingdeveloper.com/');
</script>

location.replace creates a new history entry on the visitor's browser meaning that if they hit the back button, they can get in a 'redirection loop' which is usually undesirable and may have unwanted side effects.

Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Comments

November 14. 2009 01:48

On that note... You can use either window.location.href or simply location.href.

Many people get confused between document.location and window.location. The document.location is portrayed as read only where the window.location can be altered.

However, my understanding is that Netscape and Firefox 3.5.3 allow document.location to be altered... Odd.

Cue | Reply

Add comment




(Will not be displayed!)








SponsoredTweets referral badge
Free CMS