简体   繁体   English

如何在iPhone uiwebview中处理iframe / frame dom

[英]how to handle iframes/frames dom in the iphone uiwebview

in

(void) webViewDidFinishLoad: (UIWebView*)webView (无效)webViewDidFinishLoad:(UIWebView *)webView

I inject some javascript to handle the iframes. 我注入一些JavaScript来处理iframe。 eg 例如

    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. 它告诉我iframe文档未定义。 Actually I have tried to print all the properties of contentWindow of iframe, but it's totally empty. 实际上,我尝试打印iframe的contentWindow的所有属性,但是它完全是空的。

I know the webViewDidFinishLoad may be called several times for each frame load. 我知道webViewDidFinishLoad可能会为每个帧加载多次调用。 But I can never get the iframe document. 但是我永远无法获得iframe文档。 I thought there should be at least once all the iframes are ready. 我认为所有iframe至少应该准备好一次。

Could someone please tell me how to get the iframe document to process the dom in the uiwebview? 有人可以告诉我如何获取iframe文档以在uiwebview中处理dom吗?

Thanks 谢谢

You should use postMessage Api in order to access code inside cross domain iframe. 您应该使用postMessage Api来访问跨域iframe中的代码。 Please see here for further details about how to implement this. 请参阅此处以获取有关如何实现此功能的更多详细信息。

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

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