I’m trying to pull an html variable from an iframe which is inside another div inside the iframe.
Here is the excerpt of the code I’m using:
var myVariable = $('#iframe-id').contents().find('.variable-inside').html();
The iframe has been give an id (#iframe-id) and the variable is inside “variable-inside” which is rendered inside the iframe.
For some reason this isn’t working for me. Is there a problem with the code?
I’m aware this method can be used if both documents are on the same domain (iframe doc and other doc) but I can still use it if it’s on the same domain, just different subdomains correct? Eg: iframe doc is at lorem.example.com and other doc is at ipsum.example.com)
Any help would be great. Thanks.
Communication across sub-domains is not allowed (Cross-Domain-Policy), I’ve read about ways to get around it but have not tested these.
Here’s one method: http://www.tomhoppe.com/index.php/2008/03/cross-sub-domain-javascript-ajax-iframe-etc/
The idea is to set
document.domain = "yourdomain.com"on both the parent and child pages (untested).