I'm using Mozilla Firefox's console to run some JavaScript on blog to make an organized dump of the posts on it, and store it as a string variable. The string contains about 5000 messages, so it is quite long. I want to somehow save this string on my computer; this part may be done outside using methods outside of JavaScript.
The following options come to mind:
However, I don't know how to do 1 and 2 in JavaScript, the string is too long for options 3 and 4 (3 complains about the string being too large when I expand it, 4 gets truncated), and I don't know how to do 5.
Any suggestions? Thank you in advance.
I don't know about Firefox's console, but Chrome's console exposes a copy() method that will put strings of any size on your clipboard
What you can do is the use the new HTML5 "download" attribute of an a tag. If you set the attribute to a file name, when clicked, instead of going to the file, it will download it with the file name. How does this help? Well, you can also use the 'data' scheme. If you have this:
<a href="data:text/plain,This is an example message." download="example.txt">click to download</a>
It will cause the file to download. If you use JavaScript to create the a tag, hide it, set the href to "data:text/plain,YourString", and download to "blogDump.txt", then use the click method, it will cause it to download.
EDIT: Example!
var link = document.createElement('a');
link.setAttribute('href', 'data:text/plain,Example');
link.setAttribute('download', 'example.txt');
link.click();
EDIT 2: FireFox doesn't like links that aren't in the DOM being clicked. Second example:
var link = document.createElement('a');
link.setAttribute('href', 'data:text/plain,Example');
link.setAttribute('download', 'example.txt');
document.getElementsByTagName("body")[0].appendChild(link).click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With