简体   繁体   English

将字符串另存为本地file.txt

[英]Save string as local file.txt

I want to save a string to a local file.txt 我想将字符串保存到本地file.txt

I have this HTML: 我有这个HTML:

<div class="content"></div>

and this js 和这个js

var string = 'ThisIsMyString';
var a = '<a href="data:application/octet-stream;charset=utf-16le;base64,'+ string + '">text file</a>';
$('.content').append(a);

As you can see the text 'ThisIsMyString' from var a gets saved in the file just as i wanted but the problem is that if you inspect the element you will be able to see my text inside the anchor tag. 正如您看到的那样,来自var a的文本'ThisIsMyString'被保存到文件中,就像我想要的那样,但是问题是,如果您检查元素,您将能够在anchor tag中看到我的文本。

You can check it here. 您可以在这里检查。 http://jsfiddle.net/VBJ9h/2389/ http://jsfiddle.net/VBJ9h/2389/

The question is, is there any way hide the content of the file from the a tag? 问题是,是否可以通过a标签隐藏文件的内容?

It is not possible to hide content from the Developer Console like that. 这样无法从开发人员控制台隐藏内容。

If you want to request something without revealing an explicit link you should consider using an ajax request, and some programming language to provide a back-end for sending the file to the request. 如果您想在不显示显式链接的情况下请求某些内容,则应考虑使用ajax请求和某种编程语言来提供用于将文件发送到请求的后端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM