gpt4 book ai didi

javascript - 如何根据浏览器选择 `window.URL.createObjectURL()`和 `window.webkitURL.createObjectURL()`

转载 作者:技术小花猫 更新时间:2023-10-29 12:21:52 30 4
gpt4 key购买 nike

从 Firefox 开发者网站,我知道 Firefox 使用

objectURL = window.URL.createObjectURL(file);

获取文件类型的 url,但在 chrome 和其他 webkit 浏览器中,我们有 window.webkitURL.createObjectURL() 用于检测 url。

我不知道如何基于浏览器引擎交换这个功能,我需要它在两种浏览器(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 );

关于javascript - 如何根据浏览器选择 `window.URL.createObjectURL()`和 `window.webkitURL.createObjectURL()`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11277677/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com