I have a server API which is returning a HTML response. I need to display that HTML Response in an iframe on my web page. Any idea how do i do this?
Asked
Active
Viewed 6,436 times
1
-
You may need to ask more specific problem you face while you try to implement it. Otherwise users may not be able to provide proper answer. – Coder Dec 02 '16 at 10:14
-
Please show some code that you have done so far, then other users will help you out. – Sharon Nathaniel Dec 02 '16 at 10:16
-
Check the answer [iFrame : How to display a server response (HTML) directly into iFrame using javascript?](http://stackoverflow.com/questions/15370377/iframe-how-to-display-a-server-response-html-directly-into-iframe-using-java?rq=1) – Dec 02 '16 at 10:26
1 Answers
1
So, with the limited facts I have, maybe I can crack this case. When you get your response, you'll want to get the IFrame using Javascript. But, there is no truly robust way to do this, and it is totally redundant, unless you are trying to, say, avoid some sort of UI within the response. The best way to do this would simply be taking the response, and displaying it within the current document.
This can be achieved by
<div id="response">
</div>
<script>
function write(data) {
document.getElementById("response").innerHTML = data;
}
</script>
If you absolutely need to use IFrames to display data (I highly don't recommend), this link can put you in the right direction.
jQuery/JavaScript: accessing contents of an iframe
iFrame : How to display a server response (HTML) directly into iFrame using javascript?
Edit:
Try also, noting "response" is an IFrame
document.getElementById("response").document.body.innerHTML = data;