2

I have this Json object on JavaScript:

    var case= {
        description: $("#a").val(),
        start: document.getElementById("b").textContent,
        end: document.getElementById("c").textContent,
        frequency: $("#d").val(),
        deployment: $("#e").val(),
    }
    mainFile.events.push({"id": Object.keys(manifest.events).length, case});
    localStorage.setItem('LocalStor', JSON.stringify(mainFile));

Every time I run this function I add/push a new object the the mainFile object and store it in the local storage. I can view the whole object from console and it is working, but what I want is to display it on a new tab of the browser, just like opening a JSON file on the browser.

Hussein
  • 653
  • 3
  • 10
  • 28

2 Answers2

0

You could redirect to base 64:

window.location = "data:application/json;base64,"+btoa( JSON.stringify(mainFile) );
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
  • 1
    I got this error: Not allowed to navigate top frame to data URL: data:application/json,eyJldmVudHMiOlt7Im... – Hussein Sep 20 '17 at 19:53
0

Try this

data = window.open("data:text/json," + encodeURIComponent(mainFile),
                       "_blank");
data.focus();

from Open a new tab/window and write something to it?

kemotoe
  • 1,730
  • 13
  • 27