jq 读取服务器文件,使用jQuery读取/写入文件

使用javascript的execCommand(SaveAs, false, filename);功能

编辑:不再工作。由于浏览器的安全性考虑,这个Javascript函数过去可以在所有浏览器上工作,但现在只在IE上工作。它向通过浏览器运行此功能的用户提供了“另存为”对话框,用户按OK键,该文件由服务器端的javascript保存。

// This function uses iFrame as a buffer, it fills it up with your content

// and prompts the user to save it out.function save_content_to_file(content, filename){

var dlg = false;

with(document){

ir=createElement(iframe);

ir.id=ifr;

ir.location=about.blank;

ir.style.display=none;

body.appendChild(ir);

with(getElementById(ifr).contentWindow.document){

open("text/plain", "replace");

charset = "utf-8";

write(content);

close();

document.charset = "utf-8";

dlg = execCommand(SaveAs, false, filename);

}

body.removeChild(ir);

}

return dlg;}

像这样调用函数:msg = "I am the president of tautology club.";save_content_to_file(msg, "C:\test");

使用javascript的execCommand(SaveAs, false, filename);功能 编辑:不再工作。由于浏览器的安全性考虑,这个Javascript函数过去可以在所有浏览器上工作,但现在只在IE上工作。它向通过浏览器运行此功能的用户提供了“另存为”对话框,用户按OK键,该文件由服务器端的javascript保存。 // This function uses iFrame as a buffer, it fills it up with your content // and prompts the user to save it out.function save_content_to_file(content, filename){ var dlg = false; with(document){ ir=createElement(iframe); ir.id=ifr; ir.location=about.blank; ir.style.display=none; body.appendChild(ir); with(getElementById(ifr).contentWindow.document){ open("text/plain", "replace"); charset = "utf-8"; write(content); close(); document.charset = "utf-8"; dlg = execCommand(SaveAs, false, filename); } body.removeChild(ir); } return dlg;} 像这样调用函数:msg = "I am the president of tautology club.";save_content_to_file(msg, "C:\test");
经验分享 程序员 微信小程序 职场和发展