Why are Google search results in UIWebView not triggering webViewDidFinishLoad?

泪湿孤枕 提交于 2019-12-23 20:48:21

问题


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

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.

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


回答1:


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.

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

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.

Executing that JS every few seconds should be enough.

Hope that helps



来源:https://stackoverflow.com/questions/10568661/why-are-google-search-results-in-uiwebview-not-triggering-webviewdidfinishload

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!