Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 842
SIVAKUMAR.J Avatar asked Dec 13 '10 06:12

SIVAKUMAR.J


People also ask

How do I move data from one page to another in JavaScript?

There are two ways to pass variables between web pages. The first method is to use sessionStorage, or localStorage. The second method is to use a query string with the URL.

How do I redirect to another page?

How to Redirect to Another Page in HTML. To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.

How do I switch from one HTML page to another?

Approach: To redirect from an HTML page to another page, you can use the <meta> tag by specifying the particular link in the URL attribute. It is the client-side redirection, the browsers request the server to provide another page.

How can a page be forced to load another page in JavaScript?

Approach: We can use window. location property inside the script tag to forcefully load another page in Javascript. It is a reference to a Location object that is it represents the current location of the document. We can change the URL of a window by accessing it.


1 Answers

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> 
like image 115
David Tang Avatar answered Oct 13 '22 06:10

David Tang