如何使用Javascript编写本地

如何使用Javascript编写本地

本文介绍了如何使用Javascript编写本地.txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在IE中使用javascript控制台编写.txt文件。
我已经有了我想在文件上写的字符串;所以,我想做的是:

  var refTab = document.getElementById(historymatch_tb0); 
var ttl;
for(var i = 0; row = refTab.rows [i]; i ++)
{
row = refTab.rows [i];
for(var j = 0; col = row.cells [j]; j ++)
{
WriteInFile(col.innerHTML);
}

}

我没有的是函数WriteInFile因为我把它弄得这样:

 函数WriteInFile(a)
{
var fso = new的ActiveXObject( Scripting.FileSystemObject的);
var filename =c:\\Users\\ Riccardo \\\\.txt;
var f = fso.OpenTextFile(filename,2,true);
f.WriteLine(a);
f.Close();
}

这不起作用,
脚本不给我的错误,但文件是空的,控制台显示单词:undefined!
问题出在哪里?
谢谢!

解决方案

如果我理解正确,你真正要问的是如何保留信息在会话之间的js。我理解文件如何看起来很适合该任务。但由于浏览器对文件系统的访问权限非常有限,这并不理想。



您可以在浏览器的Web中保留所需的信息,而不是使用本地文件。存储。你可以稍后来找回它。有关详细信息,请参见 / p>

I want to write a .txt file using the javascript console in IE.I already have the strings that I would like to write on the file; so, what I would like to do is:

var refTab=document.getElementById("historymatch_tb0");
var  ttl;
for ( var i = 0; row = refTab.rows[i]; i++)
{
   row = refTab.rows[i];
   for ( var j = 0; col = row.cells[j]; j++ )
   {
       WriteInFile (col.innerHTML);
   }

}

What I don't have is the function WriteInFile because I triyed this:

 function WriteInFile (a)
 {
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  var filename = "c:\\Users\\Riccardo\\a.txt";
  var f = fso.OpenTextFile(filename, 2, true);
  f.WriteLine(a);
  f.Close();
  }

this doesn't works,The script doesn't give me errors but the file is empty and The console shows the word: undefined!Where is the problem?Thanks!

解决方案

If I am understanding you correctly, what you are really asking is for a way to persist information in js between sessions. I understand how a file looks great for that task. But since browsers have a very limited access to the filesystem, that is not ideal.

Instead of using a local file, you can persist the information you need in the browser's Web Storage. You can come later and retrieve it. See http://www.html5rocks.com/en/features/storage for details

这篇关于如何使用Javascript编写本地.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:35