0

如何让图片预览与 IE 8 及更高版本一起使用?

我可以使用 JavaScript/jQuery 从输入类型“文件”中获取二进制图像数据吗?

如果我可以将数据(以正确的格式)返回到服务器,我应该能够在那里使用它,然后用 AJAX 返回它(尽管我绝对不是 AJAX 专家)。

根据我所做的研究,没有办法仅使用 javascript 在所有 IE 版本中获取图片预览(这是因为获取完整文件路径被他们视为潜在的安全风险)。我可以要求我的用户将网站添加到受信任的网站,但您通常不会要求用户篡改那些低级设置(更不用说让您的网站在用户看来可疑的最快方法是询问他们直接将您的网站添加到受信任的网站列表中。这就像发送电子邮件并要求输入密码。“相信我!我很安全!”:)

我在除 IE 之外的所有内容中都有图片预览,并且使用条件注释将 IE 特定的执行方式与我在其他浏览器中执行的方式分开没有问题。换句话说,答案甚至不必是跨浏览器,只需跨 IE(8 和 9)。我知道我以前(不知何故)见过 IE 网站使用图片预览,所以我知道必须至少有一种方法可以做到这一点......

4

1 回答 1

0

So if you need to support IE lower than 10 you could upload the file to the server using some of the existing AJAX upload components (Uploadify, Plupload, Valums AJAX Upload, Bleuimp, ...), generate and store a thumbnail on the server and send the url to the saved image to the client using JSON so that it could display it using an tag. Actually since IE supports Data URI Scheme you don't need to store the uploaded file to the server in order to generate the preview. You could directly return the resulting thumbnail image from your Preview controller action formatted as Data URI Scheme so that you could show it on the client.

Another solution if you don't have the time and resources to implement this functionality is to simply tell your users that if they want to get a realtime preview of the image that they should consider using a different web browser because your site doesn't support IE for this.

于 2012-11-09T16:16:55.260 回答