js安全性考虑不允许访问本地文件 调用activeXObject()
2015-09-18 14:08
549 查看
JS可否读写浏览器本地硬盘上的文件?
JS规范上写着:
JS是一个安全性的语言。不能访问本地硬盘。但它又提供了这样几个函数,通过以Scripting.FileSystemObject为参数调用ActiveXObject()方法来创建对象对文件进行操作。
http://blog.csdn.net/zaifendou/article/details/5733285
JS规范上写着:
JS是一个安全性的语言。不能访问本地硬盘。但它又提供了这样几个函数,通过以Scripting.FileSystemObject为参数调用ActiveXObject()方法来创建对象对文件进行操作。
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <script type="text/javascript"> var fso, f1, ts, s; var ForReading = 1; fso = new ActiveXObject("Scripting.FileSystemObject"); // 创建文件 f1 = fso.CreateTextFile("d://testfile.txt", true); // 填写一行数据 f1.WriteLine("Hello World"); f1.WriteBlankLines(1); // 关闭文件 f1.Close(); // 打开文件 ts = fso.OpenTextFile("d://testfile.txt", ForReading); // 读取文件一行内容到字符串 s = ts.ReadLine(); // 显示字符串信息 alert("File contents = ‘" + s + "‘"); // 关闭文件 ts.Close(); </script> </body> </html>
http://blog.csdn.net/zaifendou/article/details/5733285
相关文章推荐
- ARC forbids Objective-C objects in struct
- 在Json解析过程中,我为什么用object1.optInt ,和 object1.optString
- 大四上week2-4(抽象类,接口,Object类,扑克牌案例 )
- Failed to load libGL.so error libGL.so: cannot open shared object file: No such file or directory
- Objective-C对象和Core Foundation 对象
- Objective-C学习笔记(二十八)——对alloc和init的理解
- Objective-C中@property的所有属性详解
- OC基础教程4-Foundation 框架介绍
- JSONObject时间格式化
- [转载] objective-c 消息机制
- Objective-C 【集合对象内存管理】
- New和alloc的比较
- a different object with the same identifier value was already associated with the session
- Objective-C 【@property 中的copy关键字】
- OC类方法和对象方法对比
- Object-C nil NULL 和 NSNull
- OC基础教程3-继承+复合
- ubuntu安装ghc遇到的问题 缺少编译库libgmp.so.3: cannot open shared object file: No such file解决方案
- Objective-C学习大纲
- Objective-C 【copy和内存管理】