简体   繁体   中英

Get parent element of iframe if iframe src is cross domain

i have simple html webpage, guess main page domain is mainDomain.com . This webpage contain <iframe id="a1" src="http://crossdomain.com/page1.htm"> tag and this <iframe> tag src is cross domain. The <iframe id="a1" src="http://crossdomain.com/page1.htm"> contain one more <iframe> tag and thats src <iframe id="a1" src="http://mainDomain.com/page2.html">

I want to get content of <iframe id="a1" src="http://crossdomain.com/page1.htm"> , using main page or <iframe id="frame2"> . please help me ,how can i do this?

 <!doctype> <html> <head></head> <body> <h1>hello world</h1> <iframe src="http://crossdomain.com/page1.htm" id="frame1"> <h2 id="hader1" > hey dad </h2> <iframe src="http://mainDomain.com/page2.html" id="frame2"> <p>this is second frame</p> </iframe> </iframe> </body> </html> 

If i understant your question corrcectly , you wanna get contents from <iframe id="frame2"> into <iframe id="frame1"> .

and i deem that JQuery is useful way to get contents as cross-domain access.

<script>
$('#frame1').load(function(){
    $('#frame').contents().find('#hader1').text();
});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM