TAGS :Viewed: 5 - Published at: a few seconds ago

[ 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

Answer 1


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);