ScottHamper / Cookies

JavaScript Client-Side Cookie Manipulation Library
The Unlicense
1.77k stars 170 forks source link

Provide option to select which document #36

Closed cobbdb closed 9 years ago

cobbdb commented 9 years ago

It would be nice for sites that use friendly iframes to specify which document is used:

window.document.cookie

vs

window.top.document.cookie
ScottHamper commented 9 years ago

Hey Dan,

Could you explain your use case a little more so that I can get a better understanding of what you're trying to do?

It's my understanding that both the top document and the iframe would need to be on the same domain in order to do what you're describing (due to same-origin policy). If that's the case, there should not be any need to specify which document to use for Cookies.js. By setting a cookie for the domain, regardless of which document you used to set the cookie, both documents should be able to retrieve the cookie value.

Alternatively, consider including Cookies.js in both the top document and the iframe and simply do something like window.top.Cookies.set(...). Or use postMessage for more complicated/cross-origin situations. This issue does not seem like a responsibility that Cookies.js should be taking on.