Js to correctly determine the existence of a username cookie

  • 2020-03-30 01:29:53
  • OfStack

Sometimes we need to use cookie to save the user name and record the login status. How to correctly determine whether the cookie of this user exists? You can't simply use a! = ".
if(c_start == -1){ 

The correct method is: to determine whether there is a cookie named username3, use document.cookie.indexof (" username3= ") to determine, if the return value is -1, it does not exist.

Related articles: