简体   繁体   English

将事件发送到不同域上的 iFrame?

[英]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.我遇到了 iFrame 上的 contentDocument 无法访问的问题,因为它位于不同的域中,但我需要找到某种方法将触摸事件发送到 UIWebView 中此 iFrame 中的元素。

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.基本上,用户可以访问的页面像这一个,并且由于用户暂时无法点击这些手动(UIWebView的是使用AirPlay的镜像的第二屏幕上)我需要能够发送点击/ touchstart / touchend等事件上的元素用户正在访问的页面。

Is there any way to do this at all with Javascript?有什么办法可以用 Javascript 做到这一点吗? If not, is there any way to somehow extract the iFrame within UIWebView to get around this limitation?如果没有,有没有办法以某种方式提取 UIWebView 中的 iFrame 来绕过这个限制?

You can do this using the postMessage API: https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage您可以使用 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.您必须在两个窗口之间合并一个消息传递系统,处理事件以执行您想要的操作,您将无法访问 DOM,但是您应该能够通过触发每个窗口中的处理程序的事件来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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