admin管理员组文章数量:1393866
I have an iframe in my html page and I want to access some content from the page opened in this iframe.
<table border="1" width="100%" height="100%">
<tr>
<td id = "freebase_td">
<iframe id = "freebase_frame" src="" width="100%" height="400px"></iframe>
</td>
</tr>
</table>
In this web page's source,
<h1 id="page-title">
Angelina Jolie
</h1>
I want to access the content in the h1 tag with id "page-title" using javascript. Could it be possible?
I have an iframe in my html page and I want to access some content from the page opened in this iframe.
<table border="1" width="100%" height="100%">
<tr>
<td id = "freebase_td">
<iframe id = "freebase_frame" src="http://www.freebase./view/en/angelina_jolie" width="100%" height="400px"></iframe>
</td>
</tr>
</table>
In this web page's source,
<h1 id="page-title">
Angelina Jolie
</h1>
I want to access the content in the h1 tag with id "page-title" using javascript. Could it be possible?
Share Improve this question asked Oct 18, 2011 at 8:11 Saurabh SaxenaSaurabh Saxena 3,22511 gold badges35 silver badges46 bronze badges 3- 1 Possible duplicate of stackoverflow./questions/364952/… – spicavigo Commented Oct 18, 2011 at 8:16
- Are the pages on two separate domains? So, the page above and http://www.freebase./view/en/angelina_jolie? – Barry Jordan Commented Oct 18, 2011 at 8:17
- You can't. Google "same origin policy" to see why. – James Allardice Commented Oct 18, 2011 at 8:18
1 Answer
Reset to default 4You should first read about the browser's same-origin policy. This prevents javascript from a frame or window or iframe in one origin from accessing the content or scripts in another frame in a different origin. So, if your iframe is not the same origin as the page of your script, then it cannot directly access the iframe's contents.
If you have one of the latest browsers and you code both frames to cooperate (which means you have to control the javascript code in both frames), there is a new feature called window messaging that can be used to pass information between frames from different origins.
本文标签: htmlAccess crossdomain iframe elements using JavaScriptStack Overflow
版权声明:本文标题:html - Access cross-domain iframe elements using JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744083878a2588153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论