[英]How to get parent element form iframe about html file
How to get parent element form other html's iframe? 如何从其他HTML的iframe获取父元素?
i have a parent html file, and it call other html to be it's iframe as following: 我有一个父html文件,它调用其他html是iframe,如下所示:
index.html:
<iframe id ="MainPage" src="aa.html" style="overflow:auto"></frame>
<div id ="mainDiv"> abc </div>
Then in the aa.html file, i want to get the parents element in the aa.html 然后在aa.html文件中,我想在aa.html中获取parents元素
aa.html:
$(document).ready(function() {
var maindiv = window.parent.document.getElementById('mainDiv');
maindiv.height(300);
});
But it doesn't work at all when i open the index.html file... what wrong with my code? 但是当我打开index.html文件时,它根本不起作用...我的代码有什么问题?
Try this: 尝试这个:
$(document).ready(function()
{
var $mainDiv = window.parent.$('#mainDiv');
$mainDiv.height(300);
});
You also want to fix your HTML by closing the IFRAME tag: 您还想通过关闭IFRAME标签来修复HTML:
<iframe id ="MainPage" src="aa.html" style="overflow:auto"></iframe>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.