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