开发者

Sending data to a script in a container page from a script running in an embedded page

I have run into an interesting problem and am not sure if it can be resolved.

I have a JS script (say script1) running in an SVG document with lots of rectangles which has collected user-entered information like which rectangle was clicked / dat开发者_开发知识库a corresponding to the rectangle etc.

This SVG document is embedded inside an HTML page with <object> tags.

The problem is that script1 needs to pass the collected information to another JS script (say script2) running inside the container HTML page.

Does anybody know how to do that?

Further, to enhance my understanding, what if I had used <embed> or <iframe> tags; what method would have been appropriate then?


As long as the referenced svg's are on the same domain as the referencing embed/iframe/object tags then you can use window.frameElement to find the element that embedded the svg from inside the svg. You can use object_or_iframe_or_embed.contentDocument to get the referenced svg document from the HTML side. There's also the legacy method .getSVGDocument() that can be used instead of .contentDocument.

Examples of svg-to-parent calls (#1 and #2), and parent-to-svg calls (#4), for some more info see e.g the SVG Primer published by the SVG Interest Group.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜