search

Home  >  Q&A  >  body text

javascript - How to preview locally and determine the file size of locally uploaded pdf files (compatible with IE9 browser)

How to preview locally uploaded pdf files and determine the file size (compatible with ie9 browser)

ringa_leeringa_lee2739 days ago1059

reply all(1)I'll reply

  • 黄舟

    黄舟2017-07-05 10:42:29

    //文件大小可以根据此方法判断,兼容ie8,ie9,ie9以上也支持 
    function getFileSize(obj){ 
       try{
            var file = obj;
            file.select(); 
            file.blur(); 
            var path = document.selection.createRange().text; 
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            fileSize = fso.GetFile(path).size; 
            alert(fileSize);//弹出文件大小
         }catch(e){ 
           alert(e+"\n"+"如果错误为:Error:Automation 服务器不能创建对象;"+"\n"+"请按以下方法配置浏览器:"+"\n"+"请打开【Internet选项-安全-Internet-自定义级别-ActiveX控件和插件-对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本(不安全)-点击启用-确定】");
            return window.location.reload(); 
       }}
      转载链接:http://www.imooc.com/article/9593

    reply
    0
  • Cancelreply