如何在 IE8 中启用 JavaScript 文件 API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12140105/
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
How to Enable JavaScript file API in IE8
提问by saeed
I have developed a web application in asp.net, there is a page in this project which user should choose a file in picture format (jpeg, jpg, bmp,...) and I want to preview image in the page but I don't want to post file to server I want to handle it in client i have done it with java scripts functions via file API but it only works in IE9 but most of the costumers use IE8 the reason is that IE8 doesn't support file API is there any way to make IE8 upgrade or some patches in code behind I mean that check if the browser is IE and not support file API call a function which upgrades IE8 to IE9 automatically.
我在 asp.net 中开发了一个 web 应用程序,这个项目中有一个页面,用户应该选择一个图片格式的文件(jpeg、jpg、bmp...),我想在页面中预览图像但我不'不想将文件发布到服务器 我想在客户端处理它 我已经通过文件 API 使用 java 脚本函数完成了它,但它仅适用于 IE9 但大多数客户使用 IE8 原因是 IE8 不支持文件 API有什么办法可以让IE8升级或者后面的代码补丁我的意思是检查浏览器是否是IE并且不支持文件API调用一个自动将IE8升级到IE9的函数。
I don't want to ask user to do it in message I want to do it programmatically!!
even if it is possible to install a special patch that is required for file API
because customers thought it is a bug in my application and their computer knowledge is low
what am I supposed to do with this?
I also use Async File Upload Ajax Control But it post the file to server any way with ajax solution and HTTP handler but java scripts do it all in client browser!!!
following script checks the browser supports API or not
我不想要求用户在消息中执行此操作我想以编程方式执行此操作!!
即使可以安装文件 API 所需的特殊补丁,因为客户认为这是我的应用程序中的一个错误,而且他们的计算机知识很少,我该怎么办?
我也使用异步文件上传 Ajax 控件,但它使用 ajax 解决方案和 HTTP 处理程序以任何方式将文件发布到服务器,但 Java 脚本在客户端浏览器中完成所有操作!!!
以下脚本检查浏览器是否支持 API
<script>
if (window.File && window.FileReader && window.FileList && window.Blob)
document.write("<b>File API supported.</b>");
else
document.write('<i>File API not supported by this browser.</i>');
</script>
following scripts do the read and Load Image
以下脚本执行读取和加载图像
function readfile(e1)
{
var filename = e1.target.files[0];
var fr = new FileReader();
fr.onload = readerHandler;
fr.readAsText(filename);
}
HTML code:
HTML代码:
<input type="file" id="getimage">
<fieldset><legend>Your image here</legend>
<div id="imgstore"></div>
</fieldset>
JavaScript code:
JavaScript 代码:
<script>
function imageHandler(e2)
{
var store = document.getElementById('imgstore');
store.innerHTML='<img src="' + e2.target.result +'">';
}
function loadimage(e1)
{
var filename = e1.target.files[0];
var fr = new FileReader();
fr.onload = imageHandler;
fr.readAsDataURL(filename);
}
window.onload=function()
{
var x = document.getElementById("filebrowsed");
x.addEventListener('change', readfile, false);
var y = document.getElementById("getimage");
y.addEventListener('change', loadimage, false);
}
</script>
回答by tpeczek
You can't installanything special to add support for File API in IE8. What you can do is use a polyfillin order to implement this functionality in browsers that don't natively support it. Take a look at this list of HTML5 Cross Browser Polyfills(you should find something suitable for you in File API / Drag and Dropsection).
你不能安装任何特殊的东西来在 IE8 中添加对文件 API 的支持。您可以做的是使用polyfill,以便在本机不支持它的浏览器中实现此功能。看看这个HTML5 跨浏览器 Polyfills列表(你应该在文件 API/拖放部分找到适合你的东西)。
回答by saeed
After some researches i have got there is no way to Enable file API in IE8 but, i got some thing that want to share it with you .....
Not directly, HTML 5 is not supported by IE8. There is addons for Canvas, and also there is Google Chrome Frame, a plugin to add HTML 5 to IE older than 9.
As i understood , Google Chrome Frame is perfect way to use HTML5.
It increases IE speed 10 times and also it's usage is very easy and i describe it for you all members...
Google Chrome Frame
经过一些研究,我发现无法在 IE8 中启用文件 API,但是,我有一些东西想与您分享.....
不是直接的,IE8 不支持 HTML 5。有 Canvas 插件,还有 Google Chrome Frame,这是一个将 HTML 5 添加到 9 旧版 IE 的插件。
据我了解,Google Chrome Frame 是使用 HTML5 的完美方式。
它使 IE 速度提高了 10 倍,而且它的使用非常简单,我为所有成员描述了它......
Google Chrome Frame
A plugin for Internet Explorer that add to the Microsoft's browser, a full HTML 5 support and the JavaScript compiler of Chrome! A stable version was released on September 22, 2010 and a lot of sites have added the code in their pages.
用于 Internet Explorer 的插件,可添加到 Microsoft 的浏览器、完整的 HTML 5 支持和 Chrome 的 JavaScript 编译器!2010 年 9 月 22 日发布了一个稳定版本,很多网站都在他们的页面中添加了代码。
This plugin will work on Internet Explorer 6, 7 and further versions. Google wants to break a barrier that prevents the Web to evolve: the most common browser and its lack of compatibility with the new standards.
此插件适用于 Internet Explorer 6、7 和更高版本。Google 希望打破阻止 Web 发展的障碍:最常见的浏览器及其与新标准的不兼容。
When it is recognized, Internet Explorer will run under WebKit, the rendering engine of Chrome and Safari, and the it will use the ultra-fast JavaScript compiler in replacement if the IE interpreter.
当它被识别时,Internet Explorer 将在 Chrome 和 Safari 的渲染引擎 WebKit 下运行,它将使用超快的 JavaScript 编译器代替 IE 解释器。
The advantage of this plugin is great for the compatibility of web applications and will become even more useful with WebGL integrated in Webkit, which let us have applications in 3D on the browser: a very different Web! WebGL is also supported by Firefox since the version 3.7.
这个插件的优点是对 Web 应用程序的兼容性非常好,并且将在 Webkit 中集成的 WebGL 中变得更加有用,这让我们在浏览器上拥有 3D 应用程序:一个非常不同的 Web!从 3.7 版开始,Firefox 也支持 WebGL。
Since May 2011, the plugin can be installed without administrator rights, so on older version of IE which are incorporated into a server and can not be updated.
自2011年5月起,该插件无需管理员权限即可安装,因此老版本的IE浏览器并入服务器无法更新。
A tag in the code of a Web page will display a message prompting the user to download the plugin. Once it is installed, IE run as Chrome and will support HTML 5.
网页代码中的标签将显示一条消息,提示用户下载插件。安装后,IE 将作为 Chrome 运行,并将支持 HTML 5。
Features of Frame
框架的特点
The off-line mode. The and tags. Microsoft also plans to implement them in IE. Canvas. WebGL. CSS 3. JavaScript compiler. Compatibility at Acid 3 level. See the vidéo.
离线模式。和标签。微软还计划在 IE 中实现它们。帆布。WebGL。CSS 3. JavaScript 编译器。酸 3 级的兼容性。看视频。
Reaction from Microsoft
微软的反应
We were expecting that Microsoft has not appreciated really this initiative that promotes HTML 5 to the detriment of their own solution, Silverlight. The firm highlights a security problem:
我们原以为 Microsoft 并没有真正赞赏这种促进 HTML 5 损害他们自己的解决方案 Silverlight 的举措。该公司强调了一个安全问题:
Given the security issues with plug-ins in general and Google Chrome in particular, Google Chrome Frame running as a plug-in has doubled the attack area for malware and malicious scripts.
鉴于插件的安全问题,特别是 Google Chrome 的安全问题,作为插件运行的 Google Chrome Frame 使恶意软件和恶意脚本的攻击区域增加了一倍。
**
**
Chrome Frame. Automatic install. -> http://www.google.com/chromeframe/?quickenable=true
Google Chrome Frame code. -> https://developers.google.com/chrome/chrome-frame/
Chrome Frame: Developer Guide. -> http://www.chromium.org/developers/how-tos/chrome-frame-getting-started
铬框架。自动安装。-> http://www.google.com/chromeframe/?quickenable=true
Google Chrome 框架代码。-> https://developers.google.com/chrome/chrome-frame/
Chrome 框架:开发人员指南。-> http://www.chromium.org/developers/how-tos/chrome-frame-getting-started
**
**
回答by aqm
This works for me in pre IE10, i use https://github.com/eligrey/FileSaver.jsfor every other browser, note though this works it's not perfect, because it's IE and well you know what I mean
这在 IE10 之前对我有用,我对所有其他浏览器使用https://github.com/eligrey/FileSaver.js,请注意,虽然这有效但并不完美,因为它是 IE,你知道我的意思
Hope this helps
希望这可以帮助
/**
* saves File, pops up a built in javascript file as a download
* @param {String} filename, eg doc.csv
* @param {String} filecontent eg "this","is","csv"
* @param {String} mimetype eg "text/plain"
*/
function saveAs (filename, filecontent, mimetype) {
var w = window.open();
var doc = w.document;
doc.open( mimetype,'replace');
doc.charset = "utf-8";
doc.write(filecontent);
doc.close();
doc.execCommand("SaveAs", null, filename);
}