如何启用IE8的JavaScript文件API [英] How to Enable JavaScript file API in IE8

查看:220
本文介绍了如何启用IE8的JavaScript文件API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发asp.net web应用程序,还有在这个项目中的网页,其中用户应该选择以图片格式(JPEG,JPG,BMP,...)的文件,我想preVIEW图像在该网页,但我不希望发布文件服务器,我想处理它在客户端我已经通过文件API与Jav​​a脚本函数完​​成的,但它只能在IE9,但大多数的costumers使用IE8的原因是没有按IE8 'T支持文件API有没有什么办法让IE8升级或code一些补丁背后我的意思是,如果检查的浏览器是IE,而不是支持文件API调用的自动升级到IE8 IE9的功能。

我不想要求用户做它在消息我想这样做编程!

即使它是可能的安装所需的文件的API一个特殊的补丁
因为客户认为这是我的应用程序中的错误和他们的计算机知识不足
那我该怎么做呢?

我也使用异步文件上传阿贾克斯控制,但它发布文件服务器与Ajax解决方案和HTTP处理程序,但Java脚本没有办法做这一切在客户端浏览器!


下面的脚本会检查浏览器支持API与否​​

 <脚本>
如果(window.File&安培;&安培; window.FileReader和放大器;&安培; window.FileList和放大器;&安培; window.Blob)
  的document.write(< B>文件API的支持与LT; / B>中);
其他
  的document.write('< I>文件API此浏览器不支持< / I>');
< / SCRIPT>

以下脚本执行读取和加载图像

 函数ReadFile的(E1)
{
  变种文件名= e1.target.files [0];
  VAR FR =新的FileReader();
   fr.onload = readerHandler;
  fr.readAsText(文件名);
}

HTML code:

 <输入类型=文件ID =的getImage><&字段集GT;<传奇>您的图像此处< /传说>
    < D​​IV ID =imgstore>< / DIV>
< /字段集>

JavaScript的code:

 <脚本>
功能imageHandler(E2)
{
  VAR店=的document.getElementById('imgstore');
  store.innerHTML ='&下; IMG SRC ='+ e2.target.result +>';
}功能的LoadImage(E1)
{
  变种文件名= e1.target.files [0];
  VAR FR =新的FileReader();
  fr.onload = imageHandler;
  fr.readAsDataURL(文件名);
}在window.onload =函数()
{
  变种X =的document.getElementById(filebrowsed);
  x.addEventListener('变',ReadFile的,虚假的);
  变种Y =的document.getElementById(的getImage);
  y.addEventListener('变',的LoadImage,FALSE);
}
< / SCRIPT>


解决方案

您不能的安装的任何特殊,增加了对IE8中的文件API的支持。你可以做的是,为了在不支持原生的浏览器中实现此功能使用的填充工具即可。看看 HTML5跨浏览器Polyfills 名单(你应该找到适合的东西你的文件API /拖放的部分)。

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 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.

i don't want to ask user to do it in message i want to do it programmatic !!
even if it is possible 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

<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:

<input type="file" id="getimage">

<fieldset><legend>Your image here</legend>
    <div  id="imgstore"></div>
</fieldset> 

JavaScript code:

<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>

解决方案

You can't install anything special to add support for File API in IE8. What you can do is use a polyfill in 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 Drop section).

这篇关于如何启用IE8的JavaScript文件API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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