Troubleshooting website display or functionality issues in Edge on Windows 11
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a WebService that returns JSON data and I like to view it pretty printed.
a) When I put the url manually into Edge the JSON is displayed pretty printed.
b) When I open in Edge a new tab with Javascript "window.open(url)" the JSON is not formatted.
Examples
a) open https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m
-> The data is displayed Pretty printed.
b.1) I tried a fiddle: Hello World Example - JSFiddle - Code Playground
b.2) go to any page you want, open F12, the console and paste:
window.open("https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m");
-> data is not pretty printed.
Edge Version is 131. I tried also with edge://flags/#edge-json-viewer set to enable.
I guess this is a bug?
Troubleshooting website display or functionality issues in Edge on Windows 11
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
Hello Philipp
Welcome to the Microsoft Community.
This is not a bug but a result of how the Edge JSON Viewer behaves when opening a URL programmatically via window.open. Here's an explanation of what's happening and how you can address the issue:
Explanation:
Solutions:
<a href="URL" target="_blank">Open JSON</a>), which will behave like manual navigation and trigger the JSON Viewer. fetch("https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m")
.then(response => response.json())
.then(data => {
const prettyJSON = JSON.stringify(data, null, 2); // Pretty printconst newWindow = window.open();
newWindow.document.write(`<pre>${prettyJSON}</pre>`);
newWindow.document.close();
});
This fetches the JSON data, formats it nicely, and displays it in a new window or tab using <pre> tags.Summary:
Best Regards,
William.Y | Microsoft Community Support Specialist
Thanks, I implemented the change and and the users are now clicking on a simple link in the javascript/angular UI, if they decide to view the plain JSON data from the WebService and this is working fine. The JSONViewer is opening when clicking a simple link (was not opening when using window.open(...)).
Strange behaviour, thanks for the workaround, this did solve my problem.
Greetings
Philipp
Hi Philipp,
Thank you for your reply!
In fact, I'm not very dedicated at developing or coding works, from my limited understanding, this may be due to the differences between the JavaScript and HTML languages.
Kindly invite you to click "Yes" below the reply to support our community, so that in the future, other customers with similar doubts can be easier to find the post, and we may have a better chance to investigate further into this question. This will also be an important step in improving our community better!
Wish you a joyful Christmas and a prosperous New Year in advance!
Best Regards,
William.Y | Microsoft Community Support Specialist
Hi William
Thank you for the detailed answer.
I still don't understand why window.open should behave different from a click on a <a href="url" target="_blank">, I would expect the same behaviour for both.
I will create and show the user a link and make him click the link to get the better result. That is okay for me and I have workaround to implement.
I am sure this topic will pop up again in future.
Greetings and happy holidays
Philipp