javascript tutorial - [Solved-5 Solutions] How to redirect to another webpage ? - javascript - java script - javascript array
Problem:
How can we redirect the user from one page to another using jQuery or pure JavaScript?
Solution 1:
window.location.replace(...) will best simulate an HTTP redirect.
window.location.replace(...) is better than using window.location.href, because replace()does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco.
If we want to simulate someone clicking on a link, use location.href
If we want to simulate an HTTP redirect, use location.replace
For example:
Solution 2:
This answer has merely been provided as a possible solution; it is obviously not the best solution, as it requires jQuery. Instead, prefer the pure JavaScript solution.
Solution 3:
Solution 4:
This works for every browser:
Solution 5:
we also think that location.replace(URL) is the best way, but if we want to notify the search engines about our redirection (they don't analyze JavaScript code to see the redirection) we should add the rel="canonical" meta tag to your website.
Adding a noscript section with a HTML refresh meta tag in it, is also a good solution. I suggest you to use this JavaScript redirection tool to create redirections. It also has Internet Explorer support to pass the HTTP referrer.
Related Searches to javascript tutorial - How to redirect to another webpage ?
redirect url htmlredirect url phphow to redirect a url in wordpressredirect url javascripturl redirect servicehow to redirect to another page in html on button clickredirect link generatorhtml redirect w3schoolshtml auto redirect after 5 secondshtml redirect w3schoolshow to redirect to another page in html on button clickhow to redirect a url to another urlhtml redirect in bodyhtml redirect metaredirect page phpserver redirectjavascript tutorialjava scriptjavascriptjavascript arrayjavascript booklearn javascriptjavascript codejavascript editorjavascript classjavascripjavascript debuggerjavascript onlinejavascript examplesjavascript testjavascript documentjavascript sliderwhat is javascriptjavascript form validationjavascript validatorhtml javascriptjavascript alertjavascript eventsjavascript printjavascript domjavascript objectjavascript functionhref javascriptjavascript datejavascript promptjavascript onclickjavascript returnjavascript forjavascript numberjavascript confirmjavascript onchangejavascript regular expressionjavascript ifjavascript variablejavascript timerjavascript cookiejavascript getelementbyidjavascript innerhtmljavascript calljavascript regexpjavascript includesjavascript thisjavascript eval