The two domain names doamin are different, is there any way to achieve cookie sharing?

the two domain names doamin are different, is there any way to achieve cookie sharing?
Boss solution


just share. Don't think about it.

< H2 > but you can share it indirectly using the iframe method. < / H2 >

1. Now there are two domain names: a.com and b.com
2. Prepare an iframe.html file under the two domain names to manipulate cookie.
3. When operating cookie under the a.com domain name, introduce iframe.html under b.com and transfer the operation of cookie to iframe.html in the form of url suffix.

// a.com 
$.cookie('a',1,{domain:"a.com"})
$('body').append('<iframe src="//b.com/iframe.html?type=add&key=a&val=1"></iframe>')

4. Perform the cookie operation under the b.com domain name in iframe.html

// b.com  iframe.html  
let GetRequest = ()=>{ //...} //url
let {type,key,val} = GetRequest();
if(type=='add'){
    $.cookie(key,val,{
        domain:'b.com'
    })
} 
< H2 > Summary: < / H2 >

all you need to do in this step is to operate two cookie copies at the same time.

follow this step, and cookie astat1 is available under both a.com and b.com.

Menu