Use javascript to correctly determine whether a user name cookie exists _ javascript skills

Source: Internet
Author: User
Using cookies to save user names and record logon statuses, how can we determine whether the user's cookie exists? There is a good method below. You can refer to the following: Sometimes we need to use cookies to save the user name and record the login status. How can we correctly determine whether the user cookie exists? You cannot simply use! =.

The Code is as follows:


A = getCookie ("username3 ");
C_start = document. cookie. indexOf ("username3 = ");
If (c_start =-1 ){
$ ("# Login_form"). show ();
$ ("# Logined"). hide ();
}
Else {
$ ("# Login_form"). hide ();
$ ("# Logined"). show ();
$ ("# Ustr" pai.html ();
}


The correct method is to determine whether a cookie named username3 exists and use document. cookie. indexOf ("username3 =") to determine whether the cookie exists. If the returned value is-1, it indicates that the cookie does not exist.
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.