在新标签页中打开iframe中的链接

问题描述 投票:0回答:2

我已将excel文件转换为.htm文件。在excel文件中是链接。我在我的网站中嵌入了.htm文件这些链接应该在新标签页中打开,而不是在iframe中打开。

我怎样才能做到这一点? target =“_ blank”不起作用。

<iframe src="website.htm" style="border:none;" width="100%" height="300">
</iframe>

这也行不通:

<script src="https://code.jquery.com/jquery-latest.js"></script>
<iframe src="website.htm" style="border:none;" width="100%" height="300">
</iframe>
<script>
$('iframe a').attr('target', '_blank');
</script>
javascript html css excel
2个回答
0
投票

你可以试试

<iframe src="website.htm" style="border:none;" target="_top" width="100%" height="300">
</iframe>

使用jQuery:

$('iframe a').attr('target', '_blank');

0
投票

尝试如下:

var linkList = [iframeElement].contentWindow.document.getElementsByTagName("a");
for (var i = 0; i < linkList.length; i++) {
    linkList[i].target = "_blank";
}
© www.soinside.com 2019 - 2024. All rights reserved.