In a DART website/component that is in an iFrame,

2019-06-02 04:56发布

问题:

collegues,

I'm solving my previous ISSUE where I had some performance issues involving the shadow DOM and heavy JS animations that were not done in DART.

The proposed solution for this was to move my DART component into an iFrame, to restrict the shadowDOM to the DOM of only that iFrame.

Now the QUESTION:

How can I query from my DART code elements from JS:window.parent? Any ideas on how can I register listeners to onCLick of elements on the parent iFrame? (I'm using Polymer as well)

Thanks in forward

回答1:

Dart generally doesn't expose the DOM across iframe boundaries. You can communicate via postMessage though. I would suggest listening for "click" inside the iframe, then from within that handler, post a message to the window.parent.

The example in this post goes in the other direction (Dart hosting a JS child iframe), but it might be helpful: http://japhr.blogspot.com/2013/05/a-necessary-evilgood-in-dart-iframe.html