{"id":7706,"date":"2019-06-15T09:56:52","date_gmt":"2019-06-15T13:56:52","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=7706"},"modified":"2021-12-08T11:03:15","modified_gmt":"2021-12-08T16:03:15","slug":"redirect-webpage-javascript-jquery","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/redirect-webpage-javascript-jquery\/","title":{"rendered":"How do I Redirect to Another Webpage in JavaScript or jQuery?"},"content":{"rendered":"\n
It is not uncommon to find that in web development<\/a> projects you can do certain things in more than one way. If you want to redirect one web page to another using JavaScript<\/a>, you will realize there is more than one way to correctly do it depending on the scenario.<\/p>\n\n\n\n One of the major factors to determine which method to use depends on the sort of behavior that you are looking for.<\/p>\n\n\n\n There are three main ways to perform the redirect that you want albeit some of these are not true redirects.<\/p>\n\n\n\n 1. The ideal method to use is the 2. You can use the location assigned to load a page and keep the browser history allowing you to use the back button. You can use 3. This final option using Obviously, if you have included jQuery<\/a> on your project for other functionality, you have the option of using it to redirect to another web page. The following are examples of the methods you can use:<\/p>\n\n\n\n There you have it. That should get you started. Meanwhile, you can check out the official ECMAScript reference online<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" It is not uncommon to find that in web development projects you can do certain things in more than one way. If you want to redirect one web page to…<\/p>\n","protected":false},"author":1,"featured_media":7707,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,27,16],"tags":[106,170,303,320,328,333,471,543,635,638,643],"yoast_head":"\nlocation replace<\/code> method. This method simulates a redirect and replaces the current history of the page making it impossible to use the back button to reach the original page. You can use
location replace<\/code> like so:<\/p>\n\n\n\n
window.location.replace("http:\/\/local.brightwhiz");<\/code><\/pre>\n\n\n\n
location assign<\/code> like so:<\/p>\n\n\n\n
window.location.assign("http:\/\/local.brightwhiz");<\/code><\/pre>\n\n\n\n
location href<\/code> simulates clicking of a link and is not a true redirect although it can also simulate a redirect. This method also maintains the browser history allowing you to use the back button.<\/p>\n\n\n\n
window.location.href="http:\/\/local.brightwhiz";<\/code><\/pre>\n\n\n\n
Bonus; Redirect Using jQuery<\/h2>\n\n\n\n
$(location).attr('href','http:\/\/local.brightwhiz');\n\n$(window).attr('location','http:\/\/local.brightwhiz');\n\n$(location).prop('href', 'http:\/\/local.brightwhiz');<\/code><\/pre>\n\n\n\n