Zap*_*ree 4 html javascript iframe
所以基本上我有这样的东西
<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>
Run Code Online (Sandbox Code Playgroud)
然后在我的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>
Run Code Online (Sandbox Code Playgroud)
所以基本上我的问题是如何定位iframe实例的父div(div.iframe-holder)我点击"显示消息"按钮?这甚至可能吗?
我知道我可以通过源发送一个带索引的变量if iframe.html?index = 0表示第一个iframe.html?index = 1表示第二个等等但是这对我来说不是一个可行的解决方案,因为在iframe会有很多导航到不同的页面,所以传递到所有页面索引不是一个选项.
Pru*_*sse 10
做:
var iframe_parent_div = window.frameElement ? window.frameElement.parentNode : null;
Run Code Online (Sandbox Code Playgroud)