是什么的Andr​​oid的WebView loadData和loadDataWithBaseURL之间的区别 [英] What is the difference between Android webview's loadData and loadDataWithBaseURL

查看:389
本文介绍了是什么的Andr​​oid的WebView loadData和loadDataWithBaseURL之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而Android的WebView有2个方法来加载数据。

 公共无效loadData(字符串数据,字符串mime类型,字符串编码)


  

需要注意的是JavaScript的同源策略意味着脚本运行
  用这种方法加载的页面将是无法访问内容
  使用除数据以外的任何方案,包括HTTP(S)加载。至
  避免这种限制,使用loadDataWithBaseURL()与适当的
  基本URL。


 公共无效loadDataWithBaseURL(字符串的baseUrl,字符串数据,字符串mime类型,编码字符串,字符串historyUrl)


  

请注意以这种方式指定的内容可以访问本地设备文件
  (通过文件方案的URL)只有baseurl指比其他方案
  HTTP,HTTPS,FTPS,约或JavaScript的

FTP

我不知道该怎么做这些2句的意思是,当在两者之间选择?

在此先感谢


解决方案

 公共无效loadData(字符串数据,字符串mime类型,字符串编码)

在此,我们通过HTML,mime类型和编码

还有什么地方在

 公共无效loadDataWithBaseURL(字符串的baseUrl,字符串数据,字符串mime类型,编码字符串,字符串historyUrl)

在这里的baseUrl可能是基本URL,如道路资源文件夹,或SD卡或任何其他的路径,你的图像或其他媒体驻留关系到你的HTML,我不是太了解historyUrl的

accoring到的文档 [loadData] [1]


  

需要注意的是JavaScript的同源策略意味着脚本使用此方法加载的网页运行将无法访问使用比数据之外的任何方案加载的内容,包括HTTP(S)。为了避免这种情况的限制,使用 loadDataWithBaseURL()用适当的基本URL。


办法 loaddata 将只包含这是驻留在第一个参数的部分。


  

请注意以这种方式指定的内容可以访问本地设备文件(通过文件方案的URL)只有baseurl指不是HTTP,HTTPS,FTP等方案,FTPS,关于或JavaScript的


简单的上述意思是你可以从HTTP和传递的baseUrl访问数据......等

例如:我写这需要吨的形象从我的FTP或其他地方我会做HTML是通过我在BASEURL参数FTP的URL,我可以访问我的图片

The Android webview has 2 methods to load data

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

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, use loadDataWithBaseURL() with an appropriate base URL.

and

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

Note that content specified in this way can access local device files (via 'file' scheme URLs) only if baseUrl specifies a scheme other than 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.

I don't know what do these 2 sentences mean and when to select between the two ?

Thanks in advance

解决方案

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

In this we pass the HTML, mimeType and encoding

where else in

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

where baseUrl could be the base url such as the path to asset folder, or SDCard or any other path, where your images or the other media resides related to your html, and I am not much aware of historyUrl

accoring to the docs of [loadData][1]

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, use loadDataWithBaseURL() with an appropriate base URL.

means loaddata will only include the part which is resides in the first parameter.

and

Note that content specified in this way can access local device files (via 'file' scheme URLs) only if baseUrl specifies a scheme other than 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.

simple meaning of above is you can access the data from http and... other by passing the baseUrl

for example I have written HTML which required tons of image from my ftp or other place what I would do is pass the url of my ftp in baseURl parameter and I can access to my images

这篇关于是什么的Andr​​oid的WebView loadData和loadDataWithBaseURL之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆