Safari 中的 Javascript FileReader 检测
我知道 FileReader 对象在 Safari 5.0.5 中不可用。我有一个使用它的脚本,并认为我能够检测该对象是否存在来运行一些备用代码,如此处所建议的,
http://www.quirksmode.org/js/support.html
所以我的代码是,
if( FileReader )
{
//do this
}else{
//the browser doesn't support the FileReader Object, so do this
}
问题是,我已经在 Safari 中测试了它,一旦它点击if 语句我收到此错误并且脚本停止运行。
ReferenceError:找不到变量:FileReader
那么显然这不是处理它的最佳方法?知道为什么这不起作用吗?
I'm aware of the fact that the FileReader Object is not available in Safari 5.0.5. I have a script that uses it and thought that i'd just be able to detect whether the object exists to run some alternate code, as is suggested here,
http://www.quirksmode.org/js/support.html
So my code is,
if( FileReader )
{
//do this
}else{
//the browser doesn't support the FileReader Object, so do this
}
The problem is, i've tested it in Safari and once it hits the if statement i get this error and the script stops running.
ReferenceError: Can't find variable: FileReader
So obviously that's not the best way to deal with it then? Any idea why this doesn't work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信在你的情况下,你可以通过更简单的检查来逃脱:
如果你真的想要细致和挑剔,请检查类型。
I believe in your case you can get away with a simpler check:
check for the type if you really wanna be granular and picky.
你可以写
if (typeof FileReader !== "undefined")
你也可以使用 Modernizr< /a> 库来为您检查。
You can write
if (typeof FileReader !== "undefined")
You can also use the Modernizr library to check for you.
或者你可以做这样的事情。
Or you can do something like this.