简体   繁体   English

如何在不使用javascript中的activex的情况下从客户端获取文件大小?

[英]How to get file size from clientside without using activex in javascript?

Is there any other way to get file size at client side without using ActiveX in IE ? 有没有其他方法在客户端获取文件大小而不使用IE ActiveX

I am getting file size from client side but, IE opens security notification popup for ActiveX controls. 我从客户端获取文件大小,但IE打开ActiveX控件的安全通知弹出窗口。 Is there any other way to get file size or hide ActiveX popup? 有没有其他方法来获取文件大小或隐藏ActiveX弹出窗口?

Here is code for getting file size on client side. 这是在客户端获取文件大小的代码。

<html>
<body>
<form id="file">
<input type="file" id="loadfile" />
<input type="button" value="Image Size" onclick="testSize()" />
</form>
<script type="text/javascript">

function testSize(){
    var browserInfo = navigator.userAgent.toLowerCase();

    if(browserInfo.indexOf("msie") > -1){
        /* IE */
        var filepath = document.getElementById('loadfile').value;
        alert(filepath + " Test ");
        var myFSO = new ActiveXObject("Scripting.FileSystemObject");
        var thefile = myFSO.getFile(filepath);
        var imgbytes = thefile.size;
        alert( "name " +  thefile.name + "Size " +  thefile.size );
    }else{
        /* Other */
        var file = document.getElementById('loadfile').files[0];
        alert( "name " +  file.name + "Size " +  file.size );
    }
}
</script>
</body>
</html>

Thanks in advance. 提前致谢。

I got solution. 我得到了解决方案

There is no geniune problem with the code the problem is with internet explorer browser security settings. 代码没有天才问题,问题出在Internet Explorer浏览器安全设置上。 Generally you face this type of error when you want to open a text file or some excel files on a remote server 通常,当您要在远程服务器上打开文本文件或某些Excel文件时,会遇到此类错误

go to internetoptions < security < customlevel < initialize and script active x controls not marked safe for scripting and mark them enabled and i think your problem will be removed 转到internetoptions <security <customlevel <initialize和脚本活动的x控件没有标记为安全的脚本并标记它们已启用,我认为你的问题将被删除

thanks. 谢谢。

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

相关问题 如何在IE中使用javascript从客户端获取文件大小? - How to get file size from clientside using javascript in IE? 如何在IE 7/8中使用javascript从客户端验证文件大小? - How to validate file size from clientside using javascript in IE 7/8? 如何在不使用JavaScript的情况下不使用ActiveX插件的情况下生成XML文件 - How to generate XML file without using ActiveX plugin using javascript 如何从NodeJS的客户端获取上传的文件? - How to get uploaded file from clientside in NodeJS? 在不使用ActiveX的情况下,使用javascript创建/编写文本/ xml文件 - Creating/Writing a text/xml file using javascript without using ActiveX 如何在不使用ActiveX控件的情况下使用JavaScript代码打开Excel文件? - How to open excel file using JavaScript code without using ActiveX control? 使用 javascript 生成 .txt 文件而不使用 activex 和本地服务器 - Generate .txt file with javascript without using activex and local server 您可以在没有ActiveX的情况下使用Javascript执行文件IO - Can you do file IO using Javascript without ActiveX 使用javascript下载并解压缩gz文件[ClientSide] - Download and extract gz file using javascript [ClientSide] 浏览器详细信息来自javascript而不使用ActiveX控件 - Browser Details from javascript without using ActiveX controls
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM