Can JavaScript set mime type to window.open

I am trying to open a debug window in Javascript. Javascript passes the debug window to the JSON string, which the JSONView (Chrome extension) should display in a conveniently formatted format.

For this, the MIME type must be " application/json ". Is it possible to send the mime type and JSON string to window.open as a parameter in some way? I think the MIME type and content should be set to window.open, otherwise the JSONView will not start.

I tried this, but this did not work:

 var x = window.open("about:blank", 'x'); var doc = x.document; doc.open("application/json"); doc.write($(".trend_chart").attr("data-trendChart")) 
+6
source share
2 answers

The document stating that your discovery should be of type " application/json ", you cannot send it as a parameter to the window.open method , since this is out of context. Instead, the browser is the one that determines the type of file using request headers.

 window.open("http://www.yoursite.com/file.json", "mywindow"); 

You should see the json file in JSONView without any problems. If the browser still asks you to download the file, your JSONView installation will probably be broken.

+2
source

It's impossible.

You will be better off:

 console.log(JSON.parse($(".trend_chart").attr("data-trendChart"))); 
+1
source

Source: https://habr.com/ru/post/898944/


All Articles