Js method for determining whether to log on or not and determining whether to jump to the page _ javascript skills

Source: Internet
Author: User
Tags sessionstorage
This article mainly introduces how to determine whether to log on by js and determine whether to jump to the page. it involves Ajax and session skills and is very useful, for more information about how to determine whether to log on with js and redirect to the page, see the example in this article. Share it with you for your reference. The details are as follows:

Use session storage to determine whether the user is logged on, so as to determine the page to which the page is redirected.

Check whether there is a local mermerid:

function jumpTo(p, url) {    var customerId=sessionStorage.customerId;    if (customerId == undefined) {      p.attr("href", "page/Login/login.html");   } else {       p.attr("href", url);     } }  function infoJumpTo() {    var $info = $("#info");    jumpTo($info, "http://localhost/page/AmountAscension/amountAscension.html"); }  function starJumpTo() {    var $star = $("#star");    jumpTo($star, "http://localhost/page/MyAccount/myAccount.html");  }

In html, write onclick = "infoJumpTo" in the corresponding a tag.

But how does the customerID on the login page be stored in the local session?

Function confirm () {var tel = $ tel. val (); // Obtain the logon name and password var pwd = $ pwd on the page. val (); if (tel = "" | pwd = ") {// Both judgment rules are not empty (other judgment rules have been determined when they are input) alert ("No. and no password can be blank! ") Return false;} else {// if all the preceding conditions are met, the logon esb interface $. ajax ({url: config. baseServerUrl + '/account/login', // type: 'post', data: {mobile: tel, password: pwd }, // success: function (data) passed to the server (interface) {// the data returned by the server (interface) if (data. success) {// if the returned information indicates that the submitted information is correct var customerId = data. attr. customerInfo. id; // assign the user information ID in the data to the sessionStorage variable. customerId = customerId; // store the variable to the local sessionStorage, and the value is customerID window. location. href =' http://localhost/index.html '; // After correct logon, the page jumps to} else {// if the returned information indicates that the provided information is incorrect if (tel! = Data. tel) {// determines whether the user name or password is incorrect, and the corresponding information alert (data. message); $ tel. val (""); $ pwd. val (""); return false;} if (pwd! = Data. pwd) {alert (data. message); $ pwd. val (""); return false ;}}}})}}

On the logon page, people usually get used to entering information and click enter to manually click the logon button. the js code is as follows:

// Determine whether the Enter key is hit $ (document ). keyup (function (event) {if (event. keyCode = 13) {$ ("# login "). trigger ("click ");}});

I hope this article will help you design javascript programs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.