Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Redirect to a New Page using JavaScript

Posted by Viral Sarvaiya on October 16, 2010

An easy way to redirect a user to a new Page using JavaScript is to use


window.location = "http://www.devcurry.com";

However the problem with this approach is that it adds an item to your browser history. So in browsers like IE, the user can access the history by hitting the back button, which can be confusing to users, as they will redirected back and forth.

 

If you want to avoid the back button, use ‘window.location.replace’ which loads the new page and replaces the current page in the user’s History, with the new one, as shown below:


<head>
 <title>Redirect to a New Page</title>
 <script type="text/javascript">
 window.location.replace("http://www.devcurry.com");
 </script>
</head>
<body>

Now when you are redirected to the new page, there is no back button.

For More Details Click Here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: