2
iframe有问题。如何从iframe中的文档对象获取父元素
我想从iframe的内容获取父objet或父节点。
我的代码:
a.html:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
</head>
<body>
<div>
<input type="button" value="click me" onClick="parent.getIframe(document);"/>
</div>
</body>
</html>
的index.php:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script>
var getIframe = function(obj){
// Iframe Element = $(obj).parent();
//or some things likes this.
}
</script>
</head>
<body>
<div>
<div id="myId">
<iframe src="a.html"></iframe>
</div>
</div>
</body>
</html>
现在我想,当我点击 “点击我” 按钮。我想通过iframe的文档对象获取HTMLIFRAME对象元素。
我需要你的帮助。
如果我想要得到的div id包含IFRAME(“身份识别码”),当我点击“点击我”在a.html页面,我该怎么办? –
如果我想要得到div的ID包含iframe(“myId”),当我点击“点击我”在一个HTML页面,我该怎么做?现在我的解决方案是比较iframe的src属性。但我不想使用它。因为在我的页面中有很多iframe。它可以是50或50以上的iframe =>我的程序将会很慢。我觉得这不是很好的理想。当点击a.html的“点击我”按钮时。我们有页面或contentDocument或contentWindow的文档。为什么我们不能通过它们获得Element IFrame。我需要你的帮助。 –
听起来像你可能会遇到[同源政策](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy)。 – simonwo