简体   繁体   中英

How to direct an if/else statement to another page?

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

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;

To redirect in JavaScript:

 window.location = URL;

With jQuery

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

Use window.location="link url";

This will redirect the current page to the provided url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM