使用什么而不是FileReader for Safari? [英] What to use instead of FileReader for Safari?

查看:167
本文介绍了使用什么而不是FileReader for Safari?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我是网络编程的新手,所以对任何缺乏基本知识表示歉意。)

(Am new to web programming, so apologies for any lack of rudimentary knowledge.)

我的页面允许用户选择一个文件然后读取客户端和放大器;显示在页面上的文本框中。我发现这样做的最简单方法是使用FileReader对象,它在Firefox和Chrome中运行良好。

My page allows a user to select a file that is then read clientside & displayed in a textbox on the page. The easiest way I found to do this was to use a FileReader object, which works fine in Firefox and Chrome.

这在Safari(尚未)中不起作用,所以我应该怎么做?

This doesn't work in Safari (yet), so what should I do instead?

//When the eventlistener detects a change in the input file...
var file = evt.target.files[0]
var reader = new FileReader();
reader.onload = function (e){document.getElementById('data').value = e.target.result};
reader.readAsText(file);

相关注释:


  • 我正在使用Safari for windows

  • 现在页面是本地的,因为要读取的文件。 Chrome有问题,直到我使用标志--allow-file-access-from-files

推荐答案

可悲的是,我能想出的唯一答案就是占用一些额外的带宽。

Sadly, the only answer I can come up with will hog some extra bandwidth.

首先,使用像这样的东西(typeof FileReader!==undefined Modernizr 遵循支持FileReader的浏览器的正常流程。否则,通过AJAX将文件发布到回送内容的服务器端脚本。

Firstly, use something like if (typeof FileReader !== "undefined" or Modernizr to follow your normal flow for the browsers that DO support FileReader. Otherwise, POST the file via AJAX to some server-side script that echoes back the contents.

因此,对于兼容的浏览器,您可以节省一些带宽,对于不兼容的浏览器,您必须为团队选择一个。

So for compliant browsers, you get to save yourself some bandwidth and for non-compliant browsers you have to take one for the team.

这篇关于使用什么而不是FileReader for Safari?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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