我的 iframe 有问题。
我想从 iframe 的内容中获取父对象或父节点。
我的代码:
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对象元素。
我需要你的帮助。
最佳答案
您可以使用以下两个属性:
contentDocument - Returns the document object generated by a frame/iframe
contentWindow - Returns the window object generated by a frame/iframe
关于javascript - 如何从iframe中的文档对象获取父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12889761/