Sunday, May 29, 2011

Access the DOM of a SVG that is embedded by reference

You can reference SVG files via object, embed, or iframe tag. In each case, you can access the SVG DOM from within the parent document.

Use either the contentDocument property or the (deprecated) getSVGDocument function of the embedding element to access the SVG document, for example: var object = documents.getElementsByTagName('object')[0]; svgDocument = object.contentDocument;

See here for a more elaborate example. Note: For security reasons, the contents of the SVG document can be accessed from the parent document only if both documents are located in the same domain.

No comments:

Post a Comment