从Firefox开发者网站,我知道Firefox使用
- objectURL = window.URL.createObjectURL(file);
获取文件类型的URL,但在chrome和其他webkit浏览器中,我们有用于检测url的window.webkitURL.createObjectURL().
我不知道如何根据浏览器引擎交换这个功能,我需要它在两个浏览器(Chrome和Firefox)上工作,
https://developer.mozilla.org/en/DOM/window.URL.createObjectURL
解决方法
你可以定义一个包装函数:
- function createObjectURL ( file ) {
- if ( window.webkitURL ) {
- return window.webkitURL.createObjectURL( file );
- } else if ( window.URL && window.URL.createObjectURL ) {
- return window.URL.createObjectURL( file );
- } else {
- return null;
- }
- }
接着:
- // works cross-browser
- var url = createObjectURL( file );