开发者

SVG iframe embed and clickable links: how to target the _top?

开发者 https://www.devze.com 2022-12-10 11:53 出处:网络
I need to display a svg image (on which I have no control on) on a page I have control on. This svg image has 开发者_StackOverflow社区links, but when I click on them, the page is opened in the iframe.

I need to display a svg image (on which I have no control on) on a page I have control on. This svg image has 开发者_StackOverflow社区links, but when I click on them, the page is opened in the iframe. A solution would be to write target="_top" in the svg link, but I have no control on that file.

Is there a way to have the links open in the parent page (as it was a clickable image map)?


If the svg file is hosted on the same domain you can reach into it with script to do the target="_top" modification.

Something like this:

var link_elms = youriframe.contentDocument.querySelectorAll("a");
for(var i=0;i<link_elms.length;i++)
{
  link_elms[i].setAttribute("target", "_top");
}

The other option is to make a copy of the svg file so that you gain full control over it.

0

精彩评论

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