将本地图片加载到uiwebview中
我唯一的问题是,我想在 WebView 中重新加载一些图像。
因此,我添加了一个简单的 Javascript 方法,执行以下操作:
function replaceImage(id, src) {
document.getElementById('img'+id).src=src;
}
通过调用它
[webView stringByBlehBleyJAvascript:@"replaceImage(....);"];
,瞧 *rataplan* ... *鼓声* - 我可以看到新图像 - 在图像完全消失约 1 秒后。 现在我想知道 - 我加载的图像大小约为 30KByte。不要太多,至少不要太多,需要 60 秒。
我还尝试了 JS-Image-Object 来加载它,并将 dom-image-str 属性设置为加载的。相同的结果:/
dom 元素的总量约为 .. 12-15。所以 getElementById 不是瓶颈。
知道如何加载静态文件而不延迟吗?
顺便说一句:刚刚在模拟器中测试了它,因为我的手机坏了..
The only problem i have is, that i want to reload some images in the WebView.
Therefore, i added a simple Javascript Method, doing this:
function replaceImage(id, src) {
document.getElementById('img'+id).src=src;
}
call it via
[webView stringByBlehBleyJAvascript:@"replaceImage(....);"];
and voila *rataplan* ... *drum roll* - i can see the new image - right after the image disappears completaly for about 1 second.
Now i wonder - the image i load is about 30KByte in size. not too much, at least not to much it should take 60 seconds.
I also tried the JS-Image-Object to loadit, and set the dom-image-str attribute to the loadded one. same results :/
The complete amount of dom-elements are about .. 12-15. so the getElementById is not the bottle neck.
Any idea how to load a static file w/o delay?
Btw: just tested it in simulator, since my mobile is broken..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其放在 HTML 的底部:
我对一个非常小的本地存储图像也遇到了类似的问题,当通过 JavaScript 显示时,需要 2-3 秒才能显示。 ie
但是,如果图像包含在 HTML 中,它显然会被缓存。然后用JS显示的时候,立刻就显示出来了。
Put this at the bottom of your HTML:
I had a similar problem with a very small, locally stored image, when displayed via JavaScript would take 2-3 seconds to display. i.e.
However, if the image is included in your HTML, it apparently gets cached. Then when you display it with JS, it shows up immediately.
为什么不直接调用 Web 视图的
reload
方法呢?或者只是告诉 webView 以与第一次相同的方式再次加载内容。延迟可能只是因为您要求 Web 视图运行一些 JavaScript,这可能涉及一堆无关的东西。
Why not just call the web view's
reload
method?Or just tell the webView to load the content again in the same way you did the first time around. It could be that the delay is just because you're asking the web view to run some javascript, which probably involves a bunch of extraneous stuff.