如何在iphone uiwebview中处理iframes / frames dom

时间:2021-11-12 00:19:12

in

(void) webViewDidFinishLoad: (UIWebView*)webView

(void)webViewDidFinishLoad:(UIWebView *)webView

I inject some javascript to handle the iframes. e.g.

我注入了一些javascript来处理iframe。例如

    stringByEvaluatingJavaScriptFromString: 
@"try {
    var document = window.document.getElementsByTagName('iframe')[0].contentWindow.document.getElementsByTagName('frame'); 
    } catch (e) {
    alert (e.message);
    }"

It tells me the iframes document is undefined. Actually I have tried to print all the properties of contentWindow of iframe, but it's totally empty.

它告诉我iframes文档是未定义的。实际上我试图打印iframe的contentWindow的所有属性,但它完全是空的。

I know the webViewDidFinishLoad may be called several times for each frame load. But I can never get the iframe document. I thought there should be at least once all the iframes are ready.

我知道可以为每个帧加载多次调用webViewDidFinishLoad。但我永远无法获得iframe文档。我认为至少应该有一次所有的iframe准备就绪。

Could someone please tell me how to get the iframe document to process the dom in the uiwebview?

有人可以告诉我如何获取iframe文档来处理uiwebview中的dom吗?

Thanks

谢谢

1 个解决方案

#1


0  

You should use postMessage Api in order to access code inside cross domain iframe. Please see here for further details about how to implement this.

您应该使用postMessage Api来访问跨域iframe内的代码。有关如何实现此功能的更多详细信息,请参阅此处。

#1


0  

You should use postMessage Api in order to access code inside cross domain iframe. Please see here for further details about how to implement this.

您应该使用postMessage Api来访问跨域iframe内的代码。有关如何实现此功能的更多详细信息,请参阅此处。