1

I have some big json configs and want allow users to export them. The problem is JS prompt cant return a full data, so i decided to use windows.open and write. But "write" just "eat" html in json values. This answer https://stackoverflow.com/a/22055706 helped a lot.

var data = Store.export();
var url = 'data:text/json;charset=utf8,' + encodeURIComponent(data);
window.open(url, '_blank');
window.focus();

But when i try to export really large and long json everything freezes... How can i modify it to use blank url and unmodified json as text?

UPD My workaround

var myWindow = window.open("", "JSON Settings", '_blank');
myWindow.document.write('<textarea>' + escapeHTML(Store.export()) + '</textarea>');
myWindow.focus();
Community
  • 1
  • 1
user1128677
  • 479
  • 2
  • 11
  • 18

2 Answers2

1

You could include a multi-line text field in which you would place the data.

This gives it a space to go rather than just being injected into the HTML.

The user would then copy and paste the data out into their own .json file.

Jake Millington
  • 101
  • 1
  • 13
  • I used to do this, but large amounts of data has caused my browser to hang a few times, so I switched to sending the data as a download and had better results. – Jesse Kochis Aug 23 '16 at 12:22
  • Yeah. it looks great, and did what i want with html, but this kind of data - "news" transformed into "news" and broke json... – user1128677 Aug 23 '16 at 12:37
0

If you're trying to export the data, do you have any requirements prohibiting the user from downloading the data?

This lib has come in handy for me several times:

https://github.com/eligrey/FileSaver.js

Jesse Kochis
  • 766
  • 3
  • 10