user1128677 user1128677 - 3 months ago 21
JSON Question

document.write and JSON output

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 http://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();

Answer

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.

Comments