为什么IE 9不支持JavaScript功能? [英] Why IE 9 not supporting JavaScript function?

查看:103
本文介绍了为什么IE 9不支持JavaScript功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在运行时做一个检查文件大小和扩展名的函数,我已经做到了,并且在除了9之外的所有浏览器上正常工作。任何人都可以让我知道问题出在哪里?



Javascript



 < script type ='text / javascript'> 
function showFileSize(){
var input,file;

//(不能使用`typeof FileReader ===function`因为显然
//它在某些浏览器上作为object返回,所以看看它是否存在
//)。
if(!window.FileReader){
bodyAppend(p,该浏览器不支持该文件API。);
return;
}

input = document.getElementById('fileinput'); $!
$ b if(!input.files [0]){
bodyAppend(p,请在点击'Load'之前选择一个文件);
}
else {
file = input.files [0];
var sFileName = file.name;
var sFileExtension = sFileName.split('。')[sFileName.split('。')。length - 1] .toLowerCase();

bodyAppend(p,File Type+ sFileExtension +is+ file.size +bytes in size);
}
}

function bodyAppend(tagName,innerHTML){
var elm;

elm = document.createElement(tagName);
elm.innerHTML = innerHTML;
document.body.appendChild(elm);
}
< / script>



HTML



 < form action ='#'onsubmit =return false;> 
< input type ='file'id ='fileinput'>
< input type ='button'id ='btnLoad'value ='Save'onclick ='showFileSize();'>
< / form>


解决方案

IE9不支持HTML5 File API,包括 FileReader() ..



可能的解决方法是填充,下面的解决方案使用Flash来提供对文件系统的访问在不支持File API(IE和Safari)的浏览器上,但不支持拖放




  • 此处链接


  • 关于为什么FileReader不适用于IE9的参考

  • I'm trying to make a function for checking file size and extension on run time, I have done it and working properly on all browser except ie 9. Can anyone let me know where the problem?

    Javascript

    <script type='text/javascript'>
    function showFileSize() {
        var input, file;
    
        // (Can't use `typeof FileReader === "function"` because apparently
        // it comes back as "object" on some browsers. So just see if it's there
        // at all.)
        if (!window.FileReader) {
            bodyAppend("p", "The file API isn't supported on this browser yet.");
            return;
        }
    
        input = document.getElementById('fileinput');
    
       if (!input.files[0]) {
            bodyAppend("p", "Please select a file before clicking 'Load'");
        }
        else {
            file = input.files[0];
            var sFileName = file.name;
            var sFileExtension = sFileName.split('.')[sFileName.split('.').length - 1].toLowerCase();
    
            bodyAppend("p", "File Type " + sFileExtension + " is " + file.size + " bytes in size");
        }
    }
    
    function bodyAppend(tagName, innerHTML) {
        var elm;
    
        elm = document.createElement(tagName);
        elm.innerHTML = innerHTML;
        document.body.appendChild(elm);
    }
    </script>
    

    HTML

    <form action='#' onsubmit="return false;">
    <input type='file' id='fileinput'>
    <input type='button' id='btnLoad' value='Save' onclick='showFileSize();'>
    </form>
    

    解决方案

    IE9 does not support HTML5 File API, including FileReader() ..

    A possible workaround would be to polyfill, the solution below uses Flash to provide access to the filesystem on browsers that don't support the File APIs (IE and Safari), but it does not support drag-n-drop.

    这篇关于为什么IE 9不支持JavaScript功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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