如何拦截WebView中的图片加载请求?

发布于 2024-10-08 03:54:39 字数 377 浏览 0 评论 0原文

是否可以在WebView中的图像加载请求实际启动之前拦截它们并修改其URL?

例如,我

mWebView.loadUrl(myUrl);

在 onLoadResources 事件中可以看到 URL,但无法修改它们?

问题是我正在开发从远程位置加载 html 内容的应用程序。由于某种原因,作者排除了图像路径,并且在 img src 中他只有文件名。现有的 iPhone 应用程序正在使用此 html 内容,我认为该内容是以最适合 iPhone 的方式构建的。所以,我需要以某种方式弄清楚如何改变这些路径。例如,如果我选择首先下载所有图像,则需要更改路径并在 image.jpg 名称前面添加 file:///...。

谢谢。

Is it possible to intercept image load requests in WebView before they are actually started and modify their URLs?

For example, I have

mWebView.loadUrl(myUrl);

In onLoadResources event I can see URLs, but I can't modify them?

The thing is I am working on application that loads html content from remote location. For some reason author excluded image path and in img src he just have file name. Existing iPhone application is using this html content and I assume the content is build the way that is the best for iPhone. So, I need somehow to figure how to alter these paths. For example, if I choose to download all images first, I would need to alter path and add file:///... in front of image.jpg name.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

负佳期 2024-10-15 03:54:39

你可以使用onLoadResource,虽然不仅是图像,而且加载任何资源,如javascript和css

you can use onLoadResource although are not only images but any resource loaded like javascript and css

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文