- jQuery is not necessary, and 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.
- To simulate someone clicking on a link, use location.href
- To simulate an HTTP redirect, use location.replace
Below we are going to implement an alternative for IE8 & lower so that we don’t lose HTTP_REFERER. Otherwise you can almost always simply use window.location.href.
- You can use this Code:
- To works for each browser:
- Redirect to another page, you can use:
- You can’t redirect to a function. What you can do is pass some flag on the URL when redirecting, then check that flag in the server side code and if raised, execute the function.
- HTML Example for Redirecting a Page or URL
- Here is complete HTML page, which uses method to redirect a page or URL. Since you can only use one method at a time.
- This works with jQuery:
If you need to give a complete URL as window.location=”www.wikitechy.com”;