在
(void) webViewDidFinishLoad: (UIWebView*)webView
我注入(inject)一些 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 吗?
谢谢
最佳答案
您应该使用 postMessage Api 来访问跨域 iframe 内的代码。 请参阅here有关如何实现此功能的更多详细信息。
关于javascript - 如何在 iphone uiwebview 中处理 iframe/frames dom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2596403/