user3067113
user3067113

Reputation: 11

how to create cookie inside an iframe with javascript

I try my code at firefox, It works, but It does not work on chrome, chrome does not allow third party cookies, I want to create cookies with javascript inside an iframe, how can I manage this ? iframe's domain is not same with the parent , thank you

Upvotes: 0

Views: 4732

Answers (1)

Igor Benikov
Igor Benikov

Reputation: 897

The best way to interaction between parent window and iframe is postMessage. Browsers support: FF3+, IE8+, Chrome, Safari(5...), Opera10+. Take a look for documentation: https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage

/*Parent*/
iframe.contentWindow.postMessage('some content', "http://child-domain");



/*Child*/
window.addEventListener("message", function(e){
console.log(e.data)
//set cookies or other
}, false);

Upvotes: 2

Related Questions