开发者

Page reload (Webview.loadUrl) results in Javascript not being (fully) processed

The following trick for getting page's HTML content after javascript has been rendered works pretty well, when placed in the onNewPicture() of a WebView's PictureListener:

browser.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');"); 

However, for some reason it works only the first time the page is loaded. That is, the application's first such WebView.loadUrl() call gets a completely rendered version of the page.

Thereafter, if I reload/refresh the page (same exact URL), the output of HTMLOUT.showHTML() appears to be the original HTML+javascript before the page was rende开发者_如何学Cred.

The strange thing is that visually, on the WebView itself, all content is there! (albeit after a significant delay... I can see the WebView's hourglass spinning, perhaps it takes too long for Javascript to be re-processed?)

This seems to suggest either an initialization problem (in my code), a bug in WebView, or some caching principle that is well known to experienced web programmers but with which I am not familiar with yet.

But then it gets even more interesting: Subsequent calls to WebView.loadUrl() result in the aforementioned failure multiple (3-10) times until... the page is miraculously fully rendered again! (and then multiple failures again, and so on)

Which may suggest timing problem?

Any suggestion on how to debug or troubleshoot this?


you have to inject the javascript after the page loads! Took me forever to figure it out

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜