public void loadData(String data,String mimeType,String encoding)

Added in API level 1

Loads the given data into this WebView using a 'data' scheme URL.

Note that JavaScript's same origin policy means that script running in a page loaded using this method will be unable to access content loaded using any scheme other than 'data', including 'http(s)'. To avoid this restriction, useloadDataWithBaseURL() with an appropriate base URL.

The encoding parameter specifies whether the data is base64 or URL encoded. If the data is base64 encoded, the value of the encoding parameter must be 'base64'. For all other values of the parameter, including null, it is assumed that the data uses ASCII encoding for octets inside the range of safe URL characters and use the standard %xx hex encoding of URLs for octets outside that range. For example, '#', '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.Parameters

data a String of data in the given encoding
mimeType the MIME type of the data, e.g. 'text/html'
encoding the encoding of the data

使用'data'格式的URL来将制定的数据加载到WebView中。

要注意,如果使用任何非‘data’格式,包括‘http(s)’作为scheme,在页面中运行的js将不能被访问到内容;

为了避免这一点,采用一个合适的base URL来调用loadDataWithBaseURL() 是以个好的选择;

encoding指定了数据是否是base64或者URL编码。如果数据时base64编码,参数的值必须是“base64”。

对于任何其它的参数,包括null,系统会默认使用ascll码来编码URL。。。

例如'#', '%', '\', '?'必须分别被替换为%23, %25, %27, %3f

public void loadDataWithBaseURL(String baseUrl,String data,String mimeType,String encoding,String historyUrl)

Added in API level 1

Loads the given data into this WebView, using baseUrl as the base URL for the content. The base URL is used both to resolve relative URLs and when applying JavaScript's same origin policy. The historyUrl is used for the history entry.

Parameters

baseUrl the URL to use as the page's base URL. If null defaults to 'about:blank'.
data a String of data in the given encoding
mimeType the MIMEType of the data, e.g. 'text/html'. If null, defaults to 'text/html'.
encoding the encoding of the data
historyUrl the URL to use as the history entry. If null defaults to 'about:blank'.

将制定内容加载到WebView中,使用baseURl作为内容中的基地址。

这个baseUrl 不仅用于相对URL,而且也用于js的根地址。historyUrl用与指向历史记录(这个需要我们自己实现,其实就是个地址)。


需要注意的就是history所指向的必须是一个页面,并且页面存在于SD卡中或程序中(assets),loadDataWithBaseURL,它本身并不会向历史记录中存储数据,要想实现历史记录,需要我们自己来实现,也许是我的技术有限,我有了比较笨的访求来实现:就是在加载页面时,我把数据另外的写到一个html页面中,并把它保存到assest中,当点击返回时,它会通过historyUrl指向的路径来加载页面,这样就解决了历史记录问题。

上面这两种方法,我建议使用后者,虽然loadData的历史记录不需要我们自己来实现,但在使用时,我们必须把所有的%,#,\,?转换掉,而且不支持中文。















更多相关文章

  1. mybatisplus的坑 insert标签insert into select无参数问题的解决
  2. 箭头函数的基础使用
  3. python起点网月票榜字体反爬案例
  4. NPM 和webpack 的基础使用
  5. Python list sort方法的具体使用
  6. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  7. android之sqlite数据库初级
  8. Android(安卓)使用HttpGet进行登录
  9. OpenGL ES教程VI之纹理贴图(原文对照)

随机推荐

  1. android通过JNI用C/C++创建本地文件
  2. 字符串资源多国语言版本的出错问题
  3. 【Dialer】自定义暗码进入测试模式
  4. Android获得控件在屏幕中的绝对坐标
  5. Android对用五大布局
  6. Android之调用系统Email发送邮件
  7. android中度量坐标 传感器应用的开发
  8. android中渐变效果
  9. Android Handler ExecutorService(线程池
  10. 禁用Android底部虚拟按键