JavaScript: Redirecting to another page

From The Travis van der Font Wiki
Jump to: navigation, search

To simulate someone clicking on a link, use location.href:

// similar behavior as an HTTP redirect
window.location.replace("http://www.travisfont.com");

To simulate an HTTP redirect, use location.replace:

// similar behavior as clicking on a link
window.location.href = "http://www.travisfont.com";

When using with jQuery, it will simulate an HTTP redirect:

// similar behavior as clicking on a link
$(location).attr('href', "http://www.travisfont.com");