Location.href Method

Including this script on a page will immediately redirect visitors to the URL entered.

Location.replace Method

The difference between location.href and location.replace is that the former will create a new history entry on the visitors computer. This means that if they hit the back button, they can get stuck in a 'redirection loop'. This is usually undesirable and may have unwanted side effects - most pay per click search engines will not allow the submission of URLs that 'break' the back button.

Conditional Redirects with Javascript

Once you know how to redirect visitors, you can send them to different pages based on a variety of criteria. The example script below will redirect visitors with a resolution of 1024x768 or higher to a different page. Of course, there shouldn't be any reason to do so for most websites, which should work at any screen resolution ;)

Comments

MS

Sun, 03/10/2013 - 20:58

Thank you for sharing a Gold.

Thank you for sharing a Gold.=)

Mike H

Sun, 03/10/2013 - 20:58

This is a great post and gets

This is a great post and gets me close but what I need is help with script that redirects home(index) to enter page unless cookie has been set by onclick cookie set from previous visit to enter page.
I can find plenty of scripts to redirect if a cookie is present but not much on redirect if no cookie present.
Please help, I'm a javanovice and in desperate need of guidance.

You can also use this:

if(confirm("This page has been moved to a new location... would you like to be redirected?"))
{
location = "http://www.name.com";
}
else
{
history.back();
}

Rohit

Tue, 04/23/2013 - 07:47

Hi ,

Hi ,

I want to redirect users to specific links, what i mean is if original link is ABC then system should redirect it for 'Z' and if link is BAC it should redirect to 'A'..based on the orignal link system should appropriately redirect it on the fly, Can anyone suggest me a solution