javascript “未定义”不是 Safari 中的对象(正在评估“window.webkitURL.createObjectURL”)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6851725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 22:06:33  来源:igfitidea点击:

'undefined' is not an object (evaluating 'window.webkitURL.createObjectURL') in Safari

javascriptsafariwebkit

提问by eastydude5

In my Javascript code, I'm trying to check on the blob URL created by an uploaded image: alert(window.webkitURL.createObjectURL(files[0]));

在我的 Javascript 代码中,我试图检查由上传的图像创建的 blob URL: alert(window.webkitURL.createObjectURL(files[0]));

In Safari, with this line, I get the error: TypeError: 'undefined' is not an object (evaluating 'window.webkitURL.createObjectURL')

在 Safari 中,使用这一行,我收到错误消息: TypeError: 'undefined' is not an object (evaluating 'window.webkitURL.createObjectURL')

To be sure, the files[0] is being referenced correctly. When I do: alert(files[0]);

可以肯定的是,文件[0] 被正确引用。当我做: alert(files[0]);

Safari tells me: [object File]

Safari 告诉我: [object File]

So I know I have a file object being correctly referenced to - what should be - a correct WebKit URL referencing function.

所以我知道我有一个文件对象被正确引用 - 应该是什么 - 一个正确的 WebKit URL 引用函数。

Any ideas?

有任何想法吗?

回答by joken

webkitURL belongs to the File/Blob API, which is not yet supported in Safari (5.1.2) or mobile Safari (iOS 5.01).

webkitURL 属于 File/Blob API,Safari (5.1.2) 或移动版 Safari (iOS 5.01) 尚不支持该 API。

ArrayBuffers are available in recent Safaris.

ArrayBuffers 在最近的 Safaris 中可用。

回答by T.J. Crowder

I suspect you're focussing on the wrong element of that line. I'd double-check that both window.webkitURLand window.webkitURL.createObjectURLreally exist.

我怀疑您关注该行的错误元素。我会仔细检查这两个window.webkitURLwindow.webkitURL.createObjectURL真的存在。