Javascript open in new tab by using json - Stack Overflow
custom list - How Can I Get URL Column to Open in New Window in SharePoint 2016 - SharePoint Stack Exchange
Display json in a new browser tab page - javascript
Open JSON links into new browser tabs?
IMHO
why not construct the links instead on onclick
footerOptionsHtml += "<a href='"+config.footerOptions[key]+"' target='_blank'>"+key+"</a>"
Jay Swaminarayan!
Yes why not?
footerOptionsHtml += "<a class='ctd-footer-option' href='"+config.footerOptions[key]+"' target='_blank'>"+key+"</a>"
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:
- Manual URL Entry:
- When you manually input the JSON URL in Edge's address bar, Edge knows it's serving JSON content and uses its built-in JSON Viewer to pretty-print it.
- window.open() Behavior:
- When you use window.open() to programmatically open the URL, Edge does not automatically invoke its JSON Viewer. Instead, it treats the opened page as plain text or raw JSON, and the pretty-print functionality is not applied.
- Reason:
- Edge's JSON Viewer may only be triggered when the request is a direct manual navigation or when the JSON content is properly formatted and served with the correct Content-Type (application/json) header, but window.open doesn't trigger the JSON Viewer in the same way.
Solutions:
- Manually Open the URL
- The simplest workaround is to let the user click the JSON URL (e.g.,
Open JSON), which will behave like manual navigation and trigger the JSON Viewer.
- Open the JSON in a New Tab with Pretty Formatting
- You can use a JavaScript library (e.g., JSON.stringify) to pretty-print the JSON content before displaying it in a new tab or window. Example:
This fetches the JSON data, formats it nicely, and displays it in a new window or tab usingfetch("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(`${prettyJSON}`); newWindow.document.close(); });tags.
- Use an External JSON Viewer Tool
- If you frequently need to pretty-print JSON, you can use tools like:
- jsonviewer.stack.hu
- jsonformatter.org
- These tools can take raw JSON data and pretty-print it in a visually appealing manner.
- Disclaimer: This is a non-Microsoft website. The page appears to be providing accurate and safe information. Watch out for ads on the site that may advertise products frequently classified as PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.
Summary:
- The behavior you're seeing is by design and not a bug. To ensure JSON is always pretty-printed when using window.open, either fetch the data and format it programmatically (Solution 2) or let the user manually click a link (Solution 1).
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