Hey there guys :)
I need to create a page (HTML) which contains some static content, and an iframe
. The iframe
is used to contain an external page, so I am trying to 'inject' the source of the page into the document element of theiframe
.
You would ask me, why not directly set the src
attribute of the iframe
element? Well, I need to process and alter the HTML of the source page before posting it, so this is out of the question.
I should probably add that I am developing an application in Java, so I'm using Servlets for the whole thing. So, I have a servlet that makes a request to an external server and gets a page as a response. I then process the response (the HTML code of the page), and generate my page with the static content, plus an iframe
containing the modified HTML.
For this, I have tried saving the modified HTML to a temporary file, then setting the src
attribute of theiframe
to this temp file. Works as a charm, but when it comes to deleting the temp file Tomcat doesn't behave very well. So I thought about completely eliminating the file, hence injecting the HTML into the iframe at runtime. The thing is, I haven't been able to achieve anything satisfying yet. I try passing the HTML as a parameter from the Servlet to JavaScript, but it's virtually impossible as I haven't been able to "escape" any special content the page might have (scripts, css, links etc.)
I am not quite sure whether it's possible to pass a parameter from the Servlet to JavaScript, and I am not sure whether it's a good idea.
Any suggestion is welcome, and I thank you for your time :)