页面重载(Webview.loadUrl)结果在Javascript不是(完全)处理 [英] Page reload (Webview.loadUrl) results in Javascript not being (fully) processed

查看:1021
本文介绍了页面重载(Webview.loadUrl)结果在Javascript不是(完全)处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

针对JavaScript已经被渲染后获得页面的HTML内容以下伎俩在pretty好,摆在当 onNewPicture() A :的 PictureListener >的WebView <$p$p><$c$c>browser.loadUrl(\"javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');\");

然而,由于某种原因,它只能在第一次加载页。也就是说,应用程序的第一个这样的 WebView.loadUrl()通话获取页面的完全呈现的版本。

此后,如果我重新加载/刷新页面(完全相同的网址), HTMLOUT.showHTML()的输出似乎是原始的HTML + JavaScript的的的网页被渲染。

但奇怪的是,视觉的,在的WebView 本身,所有的内容是存在的! (尽管显著延迟后......我能看到的WebView沙漏纺,也许它的时间太长了Javascript功能来进行再加工?)

这似乎暗示要么是初始化问题(在我的code)中的WebView一个bug,或者是众所周知的有经验的Web程序员,但与我并不熟悉,但一些缓存的原则。

但随后它会变得更加有趣:后续调用 WebView.loadUrl()导致上述故障多(3-10)次,直到...页面被奇迹般地完全呈现又来了! (然后多个故障再次,等等)

这可能意味着计时问题?

这是如何调试或解决这个任何建议?


解决方案

您在页面加载后注入的JavaScript!带我永远搞清楚

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 rendered.

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

这篇关于页面重载(Webview.loadUrl)结果在Javascript不是(完全)处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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