var fso = new ActiveXObject("Scripting.FileSystemObject");
var ds = fso.OpenTextFile('1.txt', 1, false);
if (!ds.atendofstream){
 var sg = ds.ReadAll();
 }
ds.Close();
document.write(sg);
这个是IE上的,但是我在Chrome打开就不行了,FF也一样。
求问在这些更高级的浏览上怎么写读取txt的呢?
两种混在一起怎么写。

解决方案 »

  1.   


    表示 非常奇怪。
    我在自己机器上测试是成功的。
    可是换个地方就不行了。
    就是上传到服务器上也不行啊。
     >﹏< 这是怎么回事呢?
      

  2.   

    上传到服务器肯定是行的,如果上传正确的 话IE在你自己的机器上可以,别人不行,则是自己浏览器的安全性ActiveX设置不同导致的。
      

  3.   


    这样啊。
    本地测试通过,怎么上传服务器后又不行呢?
    这是怎么回事呢。表示看了半天了,还是没看出错在那里。
    还请版主大人给点解点解啊。说到底就是权限的问题,web页面基本上没有权限来访问本地文件,所以你需要做的是把txt文件上传到服务器,然后在后台进行读取txt文件内容的操作
      

  4.   

    你的这段JS只能在IE6下面才能正常运行,IE7/8里面就必须更改浏览器安全设置,FF/chrome则这段代码一点用处都没有
      

  5.   

    如果使用ff或chrome读取客户端文件可以这样
    <!DOCTYPE html> 
    <html> 
    <head> 
        <title>read text file</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    </head>
    <body>
        <input type="file" id="files" name="files[]" multiple />
        <output id="list"></output>    <script>
          function handleFileSelect(evt) {
            var files = evt.target.files; // FileList object        // Loop through the FileList
            for (var i = 0, f; f = files[i]; i++) {          var reader = new FileReader();          // Closure to capture the file information.
              reader.onload = (function(theFile) {
                return function(e) {
                  // Print the contents of the file
                  var span = document.createElement('span');                    
                  span.innerHTML = ['<p>',e.target.result,'</p>'].join('');
                  document.getElementById('list').insertBefore(span, null);
                };
              })(f);          // Read in the file
              //reader.readAsDataText(f,UTF-8);
              reader.readAsText(f);
            }
          }      document.getElementById('files').addEventListener('change', handleFileSelect, false);
        </script>
    </body>
    </html>