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

本文探讨了javascript的execCommand('SaveAs')函数在现代浏览器中的弃用,由于安全考虑,该函数现在仅在IE浏览器中工作。这个函数过去允许用户通过浏览器触发‘另存为’对话框,直接在服务器端保存文件。随着浏览器安全性的提升,这种方法已不再适用。文章介绍了使用iFrame作为缓冲区的替代方法,但指出这种方法也逐渐过时。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

现在这个代码是一个罕见的古董零日收藏品。// content is the data (a string) you'll write to file.// filename is a string filename to write to on server side.

// 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");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值