获取驻留在iframe中的SVG的DOM

rec*_*uze 5 javascript iframe svg

我有一个嵌入了SVG的iframe.SVG是由GraphViz生成的,所以我不能改变它.我需要的是访问父页面中的SVG DOM.

iframe的来源是

<iframe id='graph' src='gen-graph.php' /> 
Run Code Online (Sandbox Code Playgroud)

有关如何访问SVG的不同节点(文本,多边形)等的任何提示?

Eri*_*röm 4

下面是一个从父文档访问外部 svg 文档的示例。

您正在寻找的是 iframe 的 contentDocument,可以通过yourIFrameElement.contentDocument. 然后像使用普通document对象一样使用 contentDocument。