Bill
Bill

Reputation: 3823

Why are Google search results in UIWebView not triggering webViewDidFinishLoad?

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?

Upvotes: 3

Views: 909

Answers (1)

Daniel
Daniel

Reputation: 23359

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

Upvotes: 3

Related Questions