简体   繁体   中英

Sending events to an iFrame on a different domain?

I've run into the problem where the contentDocument on an iFrame is not accessible to me because it's on a different domain, but I need to find some way to send touch events to elements within this iFrame in a UIWebView.

Basically the user can access pages like this one , and due to the user being unable to click on these manually (UIWebView is on a second screen using AirPlay mirroring) I need to be able to send click/touchstart/touchend etc events to elements on whichever page the user is accessing.

Is there any way to do this at all with Javascript? If not, is there any way to somehow extract the iFrame within UIWebView to get around this limitation?

You can do this using the postMessage API: https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage

You will have do incorporate a messaging system between the two windows, handle the events to do what you want, you won't have DOM access, but you should be able to do that via events that trigger handlers in each window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM