我想打开一个IFrame内的新选项卡。我试图让触发点击事件看起来好像它是从IFrame外部启动的。模拟IFrame中的点击,打开新选项卡。
page.html中
<div>
<iframe src="page1.html">
</iframe>
page1.html
<a href="path_to_other_page" id="link_to_other_page" target="_blank">link</a>
如果用户点击,但我需要的标签自动打开上面会打开一个新标签。
<script>
parent.window.open('/path_to_other_page', '_blank'); //will open a new window rather than tab but could be blocked
$(function()
{
$("#link_to_other_page")[0].click(); //opens in new window How do make the
//click appear to be initiated from outside the iframe so a new tab opens?
});
</script>
问题: 如何模拟点击链接,以便点击似乎是从外面IFRAME启动?
############
'target =“_ blank”'? – Alex 2014-09-24 11:13:21
@Alex在iframe中不起作用。 – 2014-09-24 22:48:39
@NickMaroulis - 这根本不可能。如果您对弹出窗口(宽度,高度,隐藏地址栏等)施加限制,浏览器将决定如何处理链接。因此,用户将浏览器配置为在新选项卡中打开新窗口将会是一个问题。现在还没有办法强制一个标签放在窗户上。至于使iframe链接寄存器在帧外发生,您可以创建一个伪帧来模拟iframe的功能,同时保持标准页面功能。 – 2014-09-26 12:35:31