如何获得HTML5的window.fileReader API的跨浏览器兼容性 [英] How to get Cross Browser Compatibilty for window.fileReader API of HTML5

查看:391
本文介绍了如何获得HTML5的window.fileReader API的跨浏览器兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨Html5开发人员和HTML4开发人员也... ...



我想知道是否有任何方法可以支持IE8及以上版本的html5的window.fileReader API。



下面的代码:

  if(window.fileReader){ 
alert(支持); //在html5中工作并触发警报,但不在IE8中
}

实际上,我想在提交之前阅读文件的内容。




  • 如果支持window.fileReader,我可以使用某些条件那么

    使用HTML5遵循'A'行代码,否则如果window.fileReader不受支持,那么

    使用其他一些东西来读取文件

  • 我还想知道如何在不使用

    HTML5 fileAPI的情况下读取文件内容,但不能使用ActiveXObject。


等待回复..

解决方案

您需要多件作品检查以下支持:

  //完整文件API支持。 
if(window.FileReader&& window.File& window.FileList&& window.Blob)
{
//支持
}

else alert(不支持);

第二个要求:


我也想知道如何在不使用
HTML5 fileAPI的情况下读取文件内容,但不使用ActiveXObject。

你可以做的是这样的:


  1. 有一个iframe(你会发布到这里)
  2. >
  3. 输入file类型

  4. 当用户选择本地文件时,使用javascript将其发布到iframe(例如 document.getElementById(myForm).target =myIframe; document.getElementById(myForm).submit();

  5. iframe POST页面(可能是PHP)读取上传的文件内容并回调父页面(例如< script> window.parent.someCallbackFunction(theFileCOntents);< / script>


Hi Html5 developers and HTML4 developers too...

I want to know whether is there any way to support window.fileReader API of html5 in IE8 and above.

the code below :

if(window.fileReader){
  alert("supported"); // in html5 works and fires alert but not in IE8 
}

Actually, i want to read the contents of file before submitting.

  • Can i use some condition, if window.fileReader is supported then
    follow 'A' line of code using HTML5 , else if window.fileReader is not supported then
    use some other thing...to read the file
  • I also want to know the way to read the file contents without using
    HTML5 fileAPI... but not using ActiveXObject.

Waiting for the response..

解决方案

There are multiple pieces that you'll need to check the support of:

//Full File API support.
if ( window.FileReader && window.File && window.FileList && window.Blob )
{
    //Supported
}

else alert( "Not supported" );

Your second requirement:

I also want to know the way to read the file contents without using HTML5 fileAPI... but not using ActiveXObject.

What you could do is this:

  1. Have an iframe (you'll be posting to this)
  2. Have an input of type "file"
  3. When the user selects the local file, you use javascript to post it to the iframe (e.g. document.getElementById( "myForm" ).target = "myIframe"; document.getElementById( "myForm" ).submit();
  4. The iframe's POSTed page (Could be PHP) reads the uploaded file contents and does a callback to the parent page (e.g. <script>window.parent.someCallbackFunction( theFileCOntents );</script>)

这篇关于如何获得HTML5的window.fileReader API的跨浏览器兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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