Step in the boot, JS operation Cookie, to determine whether the user is the first time to log on the site

Source: Internet
Author: User
Tags setcookie

The previous article introduced the use of the distributed boot plugin Introjs, this article introduces the method of manipulating cookies by JS.

Step-guided function is only suitable for the first time landing site of the new users, not every time the login prompt distribution guide, then how to determine whether the user is the first time to log on the site?

Through the JS Operation browser Cookie, the method has many kinds, most of it is through JS to get to the cookie store key value pairs, and then find which key to determine the value, but this scheme is more cumbersome, now give a new idea. Manually set a field to a cookie so that you can only determine if this field is available at a time. The code is as follows:

1<script type= "Text/javascript" >2$ (document). Ready (function() {3        varNewvisitor = Isnewvisitor ();//if it's a new visitor,4        if(Newvisitor = = =true)5        {6        //Animated popup message box7Alert (' You are a new user! ‘);8 9        //tag: A message has been popped to the guest. Don't play again for 30 days .TenSetcookie ("gznotes-visited", "true", 5); One        } A      }); -  -      functionIsnewvisitor () { the      //read "message has been flagged to visitors" from a cookie -        varFLG = GetCookie ("gznotes-visited"); -         if(FLG = = = "") { -         return true; +}Else { -          return false; +         } A      } at    //Write to Cookie -      functionSetcookie (CNAME, cvalue, exdays) { -        varD =NewDate (); -D.settime (D.gettime () + (exdays*24*60*60*1000)); -        varexpires = "expires=" +d.toutcstring (); -Document.cookie = cname + "=" + Cvalue + ";" + Expires + ";p ath=/"; in      }  -      //Read Cookies to      functionGetCookie (CNAME) { +        varName = CNAME + "="; -        varCA = Document.cookie.split ('; ')); the         for(vari=0; i<ca.length; i++) { *           varc =Ca[i]; $            while(C.charat (0) = = ") c = c.substring (1);Panax Notoginseng           if(C.indexof (name) = = 0)returnc.substring (name.length,c.length); -         } the         return""; +      } A</script> the

Note running on the server side, local run no effect

Step in the boot, JS operation Cookie, to determine whether the user is the first time to log on the site

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.