[英]Get parent element of iframe if iframe src is cross domain
我有簡單的HTML網頁,猜想主頁域是mainDomain.com 。 該網頁包含<iframe id="a1" src="http://crossdomain.com/page1.htm">
標簽,而該<iframe>
標簽src是跨域的。 <iframe id="a1" src="http://crossdomain.com/page1.htm">
包含另一個<iframe>
標記,這就是src <iframe id="a1" src="http://mainDomain.com/page2.html">
我想使用主頁或<iframe id="frame2">
獲取<iframe id="a1" src="http://crossdomain.com/page1.htm">
<iframe id="frame2">
。 請幫助我,我該怎么做?
<!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>
如果我正確地理解了您的問題,則希望將內容從<iframe id="frame2">
導入到<iframe id="frame1">
。
並且我認為JQuery是獲取內容作為跨域訪問的有用方法。
<script>
$('#frame1').load(function(){
$('#frame').contents().find('#hader1').text();
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.