How to go from one page to another page using javascript?

SIVAKUMAR.J picture SIVAKUMAR.J · Dec 13, 2010 · Viewed 337.8k times · Source

From an admin page if the user is valid then the browser should go to another page.

When a user enters his user name and password, then clicks the OK button then another page is displayed and the login page is automatically closed.

How can I do this with JavaScript?

Answer

David Tang picture David Tang · Dec 13, 2010

To simply redirect a browser using javascript:

window.location.href = "http://example.com/new_url";

To redirect AND submit a form (i.e. login details), requires no javascript:

<form action="/new_url" method="POST">
   <input name="username">
   <input type="password" name="password">
   <button type="submit">Submit</button>
</form>