0

Maybe my problem is simple because there are many similar requests, but I can't find the solution to my problem.

I build an HTML-website which makes a form request to a server. The server responses with a JSON text to this iframe on the website:

<iframe name="json_result" src=""></iframe>

The problem is, that this json string is on one line and with that not human-readable. How can I make it pretty? (with breaks and tabs, like firefox is doing it normally by its own in a new tab)

I know there are solutions like JSON.stringify() or google/code-prettify, but I don't know how to get the response json text from the iframe into these functions or maybe build some css classes around the iframe which formats the incoming json automatically?

Rainflow
  • 121
  • 1
  • 8
  • Possible duplicate of [How can I pretty-print JSON using JavaScript?](https://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript) – str May 25 '18 at 08:03
  • I also found JSON.stringify(), but how do I get the content of my iframe into this function and print it instead of the json one liner on my html website? – Rainflow May 25 '18 at 08:08
  • Please add more code showing how you make the request and how the iframe is populated. – str May 25 '18 at 08:11
  • I simply make a request to a server with a form, but the response of the server is shown into an iframe as target:
    . Maybe the .onload event from iframe can help here, but I'm not good with javascript.
    – Rainflow May 25 '18 at 08:22

1 Answers1

0

It seems like you want to transform the content of the IFrame from the parent site. I don't think this is possible without reading it using AJAX instead of via an IFrame.

Patrick Szalapski
  • 8,738
  • 11
  • 67
  • 129