js访问对方手机文件夹_是否可以通过javascript访问本地文件?

if (window.ActiveXObject) {

try {

var fso = new ActiveXObject("Scripting.FileSystemObject");

fso.CopyFile("C:\\Program Files\\GM4IE\\scripts\\source.txt","C:\\Program Files\\GM4IE\\scripts\\target.txt", 1);

fso = null;

}

catch (e) {

alert (e.message);

}

}

I am getting error : "Automation server can not create object" on the line where I am creating ActiveXObject instance.

I understand that it's considered very bad to access hard-drive data using javascript but I just need it.

I am using IE8 , Greasemonkey4IE to run my javascript.

Thank you,

Mohit

******************************

function WriteFile()

{

var fso = new ActiveXObject("Scripting.FileSystemObject");

fso.CopyFile("C:\\source.txt","C:\\target.txt", 1);

}

I've put the above code inside a simple HTML page and it worked perfect.

http://www.c-point.com/JavaScript/articles/file_access_with_JavaScript.htm

You can find the similar code on above mentioned location.

I modified it a bit, tough.

But when I am trying to run it through GreaseMonkey4IE it simply spitting the same error I specified earlier.

I did it guys, but thanks a lot for your quick and helpful replies.

All I did is :

Go to Tools > Internet options > Security > Custom Level

Under the ActiveX controls and plug-ins, select Enable for Initializing and Script ActiveX controls not marked as safe.

解决方案

Using native JavaScript, no, it is not generally possible to access a local file. Using plugins and extensions like ActiveX, Flash, or Java you can get around this rule, generally with some difficulty.

For some browser and OS specific exceptions to this general rule, you might want to have a look here:

Note that as of late 2012, the FileReader API has been supported in all major browsers and provides a native JavaScript mechanism for accessing local files that the user nominates (via an input element or by dropping them into the browser).

This still cannot be used to access an arbitrary file by name/path as in the examples in the original question.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值