开发者

Is there a way to force links in an iframe to open in a new window? The iframe content is on a different domain

开发者 https://www.devze.com 2023-04-03 12:16 出处:网络
I was wondering if there is a way to get links in an iframe to open in a new wind开发者_Python百科ow.The trick is the iframe content is on a different domain, and on that domain the links open in the

I was wondering if there is a way to get links in an iframe to open in a new wind开发者_Python百科ow. The trick is the iframe content is on a different domain, and on that domain the links open in the same page. I tried adding this to the html head

<base target="_blank" />

but it still opens in the iframe. If this is impossible to do on a different domain let me know.


This requires jQuery but should work.

$(document).ready(function()
{
    var baseTag= document.createElement('base');
    baseTag.target = '_blank';
    $("iframe html head").append(baseTag);
});

If it doesn't, then it's quite possibly because you can't access the contents of an iframe through jQuery. Not sure if you can or not.

0

精彩评论

暂无评论...
验证码 换一张
取 消