admin管理员组文章数量:1331909
I am trying to open a debug window within Javascript. Javascript will pass the debug window a JSON string which JSONView (a Chrome extension) should display in a nicely formatted way.
For this to work the MIME type must be "application/json
". Is it possible to send the mime type and JSON string to window.open
as a parameter some how? I think the MIME type and content has to be set on window.open otherwise JSONView won't get triggered.
I did try this, but it 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"))
I am trying to open a debug window within Javascript. Javascript will pass the debug window a JSON string which JSONView (a Chrome extension) should display in a nicely formatted way.
For this to work the MIME type must be "application/json
". Is it possible to send the mime type and JSON string to window.open
as a parameter some how? I think the MIME type and content has to be set on window.open otherwise JSONView won't get triggered.
I did try this, but it 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"))
Share
Improve this question
edited May 8, 2014 at 7:39
hakre
198k55 gold badges447 silver badges855 bronze badges
asked Oct 10, 2011 at 2:16
Vanson SamuelVanson Samuel
2,0992 gold badges18 silver badges31 bronze badges
2 Answers
Reset to default 2The document that your opening should be of type "application/json
" you cannot send it as a parameter in the window.open
method since it's out of context. The browser instead is the one that determines the file type using the request headers.
window.open("http://www.yoursite./file.json", "mywindow");
You should see the json file within JSONView without problems. If the browser still asks you to download the file, your installation of JSONView is probably broken.
It is not possible.
You'd be better off doing:
console.log(JSON.parse($(".trend_chart").attr("data-trendChart")));
本文标签: Can JavaScript set the mime type on windowopenStack Overflow
版权声明:本文标题:Can JavaScript set the mime type on window.open - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742268881a2443926.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论