Javascript 如何获得HTML5的window.fileReader API的跨浏览器兼容性
嗨,Html5开发者和HTML4开发者也 我想知道是否有办法在IE8及以上版本中支持html5的window.fileReader API 代码如下:Javascript 如何获得HTML5的window.fileReader API的跨浏览器兼容性,javascript,html,Javascript,Html,嗨,Html5开发者和HTML4开发者也 我想知道是否有办法在IE8及以上版本中支持html5的window.fileReader API 代码如下: if(window.fileReader){ alert("supported"); // in html5 works and fires alert but not in IE8 } 实际上,我想在提交之前阅读文件的内容。 如果支持window.fileReader,我可以使用一些条件吗 使用HTML5遵循“A”行代码,否则如果不支
if(window.fileReader){
alert("supported"); // in html5 works and fires alert but not in IE8
}
实际上,我想在提交之前阅读文件的内容。
- 如果支持window.fileReader,我可以使用一些条件吗
使用HTML5遵循“A”行代码,否则如果不支持window.fileReader,则
使用其他东西…读取文件 - 我还想知道不使用
HTML5文件API。。。但不使用ActiveXObject
等待响应。您始终可以使用try-catch检查浏览器中是否支持FileReader()
try {
var reader = new FileReader();
//do something
}
catch(e) {
alert("Error: seems File API is not supported on your browser");
//do something
}
您可以使用简单的if逻辑检查功能,并将您的功能包装在那里
if ('FileReader' in window) {
// Do something with FileReader since it's supported
} else {
// Do something with your polyfill solution
}
您可以尝试像这样的polyfill解决方案(适用于IE8):
您需要检查多个部件的支持情况:
//Full File API support.
if ( window.FileReader && window.File && window.FileList && window.Blob )
{
//Supported
}
else alert( "Not supported" );
你的第二个要求:
我还想知道不使用
HTML5文件API。。。但不使用ActiveXObject
你能做的是:
document.getElementById(“myForm”).target=“myIframe”;document.getElementById(“myForm”).submit();
window.parent.someCallbackFunction(theFileCOntents);
)