开发者

How to make a link open in tabbed or new window without target attribute?

In my application an external website places link in my web page and the link does not have target=_blank. More specifically its iframe in my webpage whose src is another domain which I have no control. The content in this iframe contains links that opens in the same window wiping off my ajax driven web page and taking the user to the other domain. Is there a way to intercept this ( via javascript? ) and make the link open in another wi开发者_开发技巧ndow or browser tab? It would be even much better if the link opens within the same iframe on my webpage. Is this possible? Is target="_self" makes the link open in the same iframe?


You could add the target-attribute to all a-tags in the iframe. This can be done in jQuery, like:

$("a", ".myIframe").attr("target", "_blank");

This is just pseudo-code. See here, how to access elements in an iframe:

jQuery/JavaScript: accessing contents of an iframe


** To open an url in a new tab with target attribute

<a target="_blank" href="http://www.google.com" title="">
Click here for new tab
</a>

** To open an url in a new tab without target attribute.

<a onclick="window.open(this.href,'')" 
href="http://www.google.com"  title="">
Click here for new tab withouth target attribute</a>

** To open an url in the same frame.

<a target="_self" href="https://jsfiddle.net/" title="">
Click here to open in the same frame</a>

Please find the jsfiddle it works fine
jsfiddle

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜