为什么 UIWebView 中的 Google 搜索结果不会触发 webViewDidFinishLoad? [英] Why are Google search results in UIWebView not triggering webViewDidFinishLoad?

查看:33
本文介绍了为什么 UIWebView 中的 Google 搜索结果不会触发 webViewDidFinishLoad?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这无疑是一个关于网页的更普遍的问题,但 Google 内容很容易证明这一点.

This is no doubt a more generic issue regarding web pages, but it is easily demonstrated with Google content.

在 Google 主页上输入某些搜索条件时,结果不会触发 webViewDidFinishLoad 方法.当彩色 Google 徽标替换为一些链接到专题页面的艺术品时,也会出现同样的问题.

When entering some search criteria on Google's home page the results are not triggering the webViewDidFinishLoad method. The same problem occurs when the coloured Google logo is replaced with some artwork linked to a feature page.

我怀疑由于某些 javascript 或 ajax 代码,页面没有完全加载,那么有没有办法检测到这种情况?

I suspect the page is not being fully loaded due to some javascript or ajax code, so is there a way of detecting this?

推荐答案

这是因为 Google 使用 AJAX 来做到这一点,当有效地将新资源加载到 webview 时会调用 webViewDidFinishLoad 委托方法 - 相当于一个页面在您的浏览器中加载,因为 Google 正在 AJAX 处理这些东西,所以它不会导致该方法被触发.

This is because Google are using AJAX to do this, the webViewDidFinishLoad delegate method is called when effectively a new resource is loaded into the webview - the equivalent to a page load in your browser, since Google are AJAXing this stuff, it isn't causing that method to get triggered.

没有任何方法可以检测页面的某些部分何时被加载(javascript、样式表或 ajax 响应).

There isn't any way to detect when parts of a page are loaded (javascripts, style sheets or ajax responses).

您可以做的一件事是在 Web 视图上执行一行 javascript 来告诉您页面的高度,通过等到页面的高度更改您可以知道结果何时发生,您将必须设计其他一些 - 当然在修改搜索查询时进行更智能的检查,但我的想法适用于第一个结果页面的初始 google 徽标屏幕.

One thing you could be able to do is execute a line of javascript onto the web view that tells you the height of the page, by waiting until the height of the page changes you could know when a result has occurred, you will have to devise some other - more smart check of course when a search query is modified, but my idea would work for the initial google logo screen to the first results page.

每隔几秒执行一次该 JS 就足够了.

Executing that JS every few seconds should be enough.

希望有帮助

这篇关于为什么 UIWebView 中的 Google 搜索结果不会触发 webViewDidFinishLoad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆