Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  96] [ 4]  / answers: 1 / hits: 39582  / 11 Years ago, mon, march 11, 2013, 12:00:00

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


More From » iframe

 Answers
29

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


[#79686] Saturday, March 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kadinl

Total Points: 321
Total Questions: 117
Total Answers: 103

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
;