简体   繁体   English

为什么IE 9不支持JavaScript功能?

[英]Why IE 9 not supporting JavaScript function?

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? 我正在尝试提供一种在运行时检查文件大小和扩展名的功能,我已经做到了,并且可以在除9外的所有浏览器上正常工作。有人可以让我知道问题出在哪里吗?

Javascript Java脚本

<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 的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() .. IE9不支持HTML5 File API,包括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 . 一种可能的解决方法是polyfill,下面的解决方案使用Flash在不支持File API(IE和Safari) 但不支持drag-n-drop的浏览器上提供对文件系统的访问。

Instead, clone the input, place the clone where the original is, and move the original into a hidden form. 而是克隆输入,将克隆放置在原始副本的位置,然后将原始副本移动到隐藏的形式。 You might have to use an iframe for this. 您可能需要为此使用iframe。

This would certainly work but involves some coding. 当然可以,但是需要一些编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM