Windows 和 Android 之间有冲突吗?

发布于 2024-10-20 13:33:57 字数 790 浏览 0 评论 0原文

请帮我解决这个文件路径冲突:

如您所知,许多 HTML 页面使用以“/”开头的相对路径作为 link 标记的 href 属性。例如:link href="/links/style.css"

在我的代码中,我使用 loadDataWithBaseURL 用于 WebView 设置相对路径名。如果我这样给出:

String webContent=//whole html page;
mWebView.loadDataWithBaseURL("file:///sdcard/mibook/pg90/",new String(webContent), "text/html", "UTF-8","" );

结果:在 WebView 中没有效果,因为(我觉得)附加到路径名时需要两个 '/'

如果我通过从 href 标记中删除第一个 "/" 来编辑 HTML 页面,则 WebView 会正确呈现。

但我的问题是我不想像上面那样编辑 HTML 内容。有什么解决办法吗?

Please help me solve this file path conflict:

As you know, many HTML pages use relative paths starting with a "/" for the href attribute of link tags. For example: link href="/links/style.css".

In my code, I'm using loadDataWithBaseURL for a WebView to set a relative path name. If I give like this:

String webContent=//whole html page;
mWebView.loadDataWithBaseURL("file:///sdcard/mibook/pg90/",new String(webContent), "text/html", "UTF-8","" );

Result: No effect in WebView because (I felt) it takes two '/' while appending to pathname.

If I edit my HTML page by removing the first "/" from the href tag, then the WebView renders properly.

But my problem is that I don't want to edit HTML content as above. Any solution?

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

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

发布评论

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

评论(1

空心空情空意 2024-10-27 13:33:57

loadDataWithBaseURL 状态:

Note for post 1.0. Due to the change in the WebKit, the access to asset files through   
"file:///android_asset/" for the sub resources is more restricted. If you provide null 
or empty string as baseUrl, you won't be able to access asset files. If the baseUrl is
anything other than http(s)/ftp(s)/about/javascript as scheme, you can access asset 
files for sub resources

所以基本上只允许 file:///< /code> 方案是 file:///android_asset/ 其中文件位于您的资产文件夹中。

Javadoc of loadDataWithBaseURL states:

Note for post 1.0. Due to the change in the WebKit, the access to asset files through   
"file:///android_asset/" for the sub resources is more restricted. If you provide null 
or empty string as baseUrl, you won't be able to access asset files. If the baseUrl is
anything other than http(s)/ftp(s)/about/javascript as scheme, you can access asset 
files for sub resources

So basically only allowed URL for file:/// scheme is file:///android_asset/ where files are in your asset folder.

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