`
wanggp
  • 浏览: 147547 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

WebView中loadDataWithBaseURL与loadData加载本地html困惑

阅读更多

      当使用webView.loadData(bodyBuffer.toString(), "text/html", "utf-8")加载本地的html代码时,如果html代码中%,则页面不能显示,显示为web page not availableness.而使用webView.loadDataWithBaseURL("about:blank",bodyBuffer.toString(), "text/html", "utf-8",null);即可正常加载,不知道为什么?期待找到正解。

分享到:
评论
1 楼 tracy061 2012-08-01  
    loadData:

public void loadData (String data, String mimeType, String encoding)
Load the given data into the WebView. This will load the data into WebView using the data: scheme. Content loaded through this mechanism does not have the ability to load content from the network.

Parameters
data A String of data in the given encoding. The date must be URI-escaped -- '#', '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.
mimeType The MIMEType of the data. i.e. text/html, image/jpeg
encoding The encoding of the data. i.e. utf-8, base64


下如API中所说的,

       data:是要加载的数据类型,但在数据里面不能出现英文字符:'#', '%', '\' , '?' 这四个字符,如果有的话可以用 %23, %25, %27, %3f,这些字符来替换,在平时测试时,你的数据时,你的数据里含有这些字符,但不会出问题,当出问题时,你可以替换下。

        %,会报找不到页面错误,页面全是乱码。乱码样式见符件。

        #,会让你的goBack失效,但canGoBAck是可以使用的。于是就会产生返回按钮生效,但不能返回的情况。

        \ 和? 我在转换时,会报错,因为它会把\当作转义符来使用,如果用两级转义,也不生效,我是对它无语了。



以上转自:http://bbs.chinaunix.net/thread-3617508-1-1.html

因为%在loadData中是非法字符。
希望对您有用

相关推荐

Global site tag (gtag.js) - Google Analytics