jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.12k stars 269 forks source link

Ability to define custom events for communicating across domains #131

Closed alpeshgaglani closed 9 years ago

alpeshgaglani commented 9 years ago

I am wondering what's the best way to define custom events. For example, I have the "slave" domain that has auth cookies for communicating with my API tier. I want to trigger a logout event from my "master" domain that will tell the "slave" domain to clear out the cookies. Is it a good idea to do so? What would be the best way to go about it?

jpillora commented 9 years ago

On browsers that allow 3rd party cookies (Safari doesn't) you could simply make an XHR call to slave.com/logout and have the slave server Set-Cookie:`(blank). If you want it to work across all browsers, you'll have to **redirect** toslave.com/logout` (this way you're not in an iframe and you're not affected by same-origin policy).