Reputation: 153
How do I direct a user to another page if the if statement comes true?
For example, the javascript below. If the login details are correct, I want the user to be directed to another page of the website, for example "#page5".
The code is what I currently have which only notifies the user and then redirects back to my index page. However, I want to direct it them to a specific page of the app.
function renderList(tx, results) {
if (results.rows.length > 0) {
navigator.notification.alert('Login, Success!');
} else {
navigator.notification.alert('Incorrect! Please try again.');
}
}
Thanks
Upvotes: 0
Views: 2118
Reputation: 587
To redirect in JavaScript:
window.location = URL;
With jQuery
$(location).attr('href', URL);
Upvotes: 1
Reputation: 65796
The global window
object contains the document that is currently loaded. It has a property called location
that contains the path of the currently loaded resource. Changing this property loads up the resource at the new path into the current window:
window.location = newURL;
This is such a simple operation that using jQuery would only make it more involved:
$(window)[0].location = newURL;
Upvotes: 2
Reputation: 3675
Use window.location="link url";
This will redirect the current page to the provided url.
Upvotes: 1