Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get DOM of SVG residing in iframe

I have an iframe that has an SVG embedded in it. The SVG is generated by GraphViz so I can't change much in it. What I need is access to the SVG DOM in the parent page.

The source of the iframe is

<iframe id='graph' src='gen-graph.php' /> 

Any hints on how I can get access to the different nodes (text, polygon) etc of the SVG?

like image 301
recluze Avatar asked Oct 11 '22 17:10

recluze


1 Answers

Here's an example that reaches into an external svg document from the parent document.

What you're looking for is the iframe's contentDocument, which can be accessed via yourIFrameElement.contentDocument. Then use contentDocument as you'd use the normal document object.

like image 164
Erik Dahlström Avatar answered Oct 13 '22 11:10

Erik Dahlström