所以基本上我有这样的东西
<div class="iframe-holder">
<span></span>
<iframe src="iframe.html" width="200" height="200"
</div>
<div class="iframe-holder">
<span></span>
<iframe src="iframe.html" width="200" height="200"
</div>
<div class="iframe-holder">
<span></span>
<iframe src="iframe.html" width="200" height="200"
</div>
<script>
function where_am_i(iframe_parent_div,msg){
$(iframe_parent_div).find('span').html(msg);
}
</script>
然后在我的 iframe-holder.html 中我基本上有这个
<a href="#" id="msg">Show Message In Parent Div</a>
<script>
//i want to basically imp
$('msg').click(function(event){
event.preventDefault();
var iframe_parent_div=???;//how do I get this?
parent.where_am_i(iframe_parent_div,'This is where this iframe is');
});
</script>
所以基本上我的问题是如何定位我单击“显示消息”按钮的 iframe 实例的父 div (div.iframe-holder)?这可能吗?
我知道我可以通过源发送一个带有索引的变量,即第一个 iframe.html?index=0?第二个 iframe.html?index=1 等等,但这对我来说不是一个可行的解决方案,因为在iframe 将会有很多导航到不同的页面,因此不能选择将索引传递到所有页面。
Do:
var iframe_parent_div = window.frameElement ? window.frameElement.parentNode : null;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)