How to redirect to another webpage?


WARNING: 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.

$(location).attr('href', '')

How can I redirect the user from one page to another using jQuery or pure JavaScript?

How to go to a URL using jQuery?

//As an HTTP redirect (back button will not work )

//like if you click on a link (it will be saved in the session history, 
//so the back button will work as expected)
window.location.href = "";

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.

For example:

document.location = "MyPage.php?action=DoThis";

Then in your PHP code check for "action" in the query string and if equal to "DoThis" execute whatever function you need.

Try these:

  1. window.location.href = '';
  2. window.location.assign("");
  3. window.location = '';

For more see this link: other ways to reload the page with JavaScript

How do I redirect with Javascript?

To redirect to another page, you can use:

window.location = "";

window.location is just what you need. Other thing you can do is to create anchor element and simulate click on it

$("<a href='your url'></a>").click();