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

发布于 2024-08-28 01:20:44 字数 584 浏览 5 评论 0原文

(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在巴黎塔顶看东京樱花 2024-09-04 01:20:44

您应该使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文