Two children share the cookie domain name under the same domain name

There are two domain names

sacom and sbcom;

They belong to a domain name under a domain name, not cross-domain;

The former is backstage management system, have a login page; the latter official network, there is no sign-on capabilities;

Now demand is: after background login, the official website also needs to display login status, backstage after the exit, the official website will also display the log out;

So we only need to write code to add and delete the cookie in the former domain name.

 

Add cookie

// successful callback 
Success: function (Data) { 
    $ .each (Data, function (ELE, index) { 
      // ELE is the key; index is a value 
      AddCookie (ELE, index); 
      the setCookie (ELE, index,. 1); // this third argument must be passed 
    }); 
} 

function AddCookie (the objName, objValue, objHours) {// add the current domain Cookie 
   var = the objName STR + "=" + Escape (objValue); 
   IF (objHours> 0) {// not set to 0 when the time expires, the browser cookie closed automatically disappear 
     var = new new DATE a Date (); 
     var = objHours MS * 3600 * 1000; 
     date.setTime (date.getTime () + MS); 
     STR = + "; Expires =" + date.toGMTString (); 
   } 
   the document.cookie = STR; 
} 
 
function the setCookie (c_name, value, expiredays) {// set to the same level domain cookie
    var = new new exdate a Date ();  
    exdate.setDate (exdate.getDate () + expiredays);   
    document.cookie = c_name + "=" + Escape (value) + ((expiredays == null) "": ";? the Expires =" + exdate.toGMTString () + "; path = /; domain = .b.com") // domain value (omitted prefix before the domain name must be added). 
}  


Clear cookie

// clear all Cookie 
var = document.cookie.match Keys (/ [^ =;] + (= \ =) / G?); 
IF (Keys) { 
      for (var = keys.length I; i--;) { 
          the document.cookie = Keys [I] + '= 0; Expires =' + new new a Date (0) .toUTCString (); 
          the document.cookie = Keys [I] + '= 0; path = /; .B = Domain. com; expires = '+ new Date (0) .toUTCString (); // Clear or under a specified domain, e.g. .kevis.com value of the domain (and the same is added, omitted prefix before the domain name must be added. ) 
    }
}

  

Guess you like

Origin www.cnblogs.com/chensv/p/10986270.html