简体   繁体   中英

Open Links in an iframe in a new tab

I have converted an excel file to an .htm file. In the excel file are links. I have embedded the .htm file in my website These links should be open in a new tab and not in the iframe.

How can I do this? target="_blank" didn't work.

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

This also not worked:

<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>

You could try

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

Using jQuery:

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

Try it like below:

var linkList = [iframeElement].contentWindow.document.getElementsByTagName("a");
for (var i = 0; i < linkList.length; i++) {
    linkList[i].target = "_blank";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM