简体   繁体   中英

Save string as local file.txt

I want to save a string to a local file.txt

I have this HTML:

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

and this 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.

You can check it here. http://jsfiddle.net/VBJ9h/2389/

The question is, is there any way hide the content of the file from the a tag?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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