Dynamically set document.domain to iframe
iframe, javascript
Solution
I do not know if it will help but i use this in iframe
try {
var domainName = window.parent.parent.iframeData.domainName;
}
//Access violation
catch (err) {
document.domain = window.location.hostname.replace('www.', '');
}
So i check if domain already set we have exception ang try to guess domain, in either case, there is no need to set a domain
EDIT: More correctly to use post message to set domain if needed
Problem
I have an iframe that injects in pages, called him "helper". So due to same origin policy I need to set iframe domain the same is parent window domain. But I can't get access to parent window domain. How can it be solved? This code is currently working for 2nd level domains: ``` pathArray = window.location.host.split('.'); var arrLength = pathArray.length; var domainName = pathArray.slice(arrLength - 2, arrLength).join('.'); document.domain = domainName; ``` but I need to somehow get it from parent window rather than relying on 2nd level domain