如何在 iphone uiwebview 中处理 iframe/frames dom
在
(void) webViewDidFinishLoad: (UIWebView*)webView
我注入一些 javascript 来处理 iframe。例如,
stringByEvaluatingJavaScriptFromString:
@"try {
var document = window.document.getElementsByTagName('iframe')[0].contentWindow.document.getElementsByTagName('frame');
} catch (e) {
alert (e.message);
}"
它告诉我 iframes 文档未定义。实际上我尝试打印 iframe 的 contentWindow 的所有属性,但它完全是空的。
我知道每个帧加载可能会调用 webViewDidFinishLoad 多次。但我永远无法获取 iframe 文档。我认为至少在所有 iframe 准备好后应该有。
有人可以告诉我如何获取 iframe 文档来处理 uiwebview 中的 dom 吗?
谢谢
in
(void) webViewDidFinishLoad: (UIWebView*)webView
I inject some javascript to handle the iframes. e.g.
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.
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.
Could someone please tell me how to get the iframe document to process the dom in the uiwebview?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 postMessage Api 来访问跨域 iframe 内的代码。
有关如何实现此功能的更多详细信息,请参阅此处 。
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.