0

I am trying to fetch data using the jquery ajax library and I want to add the returned html data to a frame object (without setting the source attribute). The general idea is that I want to showcase the html content as a seperate document in a frame. I tried putting the data into a div but this had the effect of affecting the main document. Thanks!

The frame is:

    <frame id="test"> 
</frame>

$.ajax({ url : url })
.done(function(html) { document.getElementById('test').innerHTML = html });

The problem seems to be that the getElementById function is return Null. This problem is resolved if I change the frame to a div.

Rajiv Nair
  • 187
  • 1
  • 3
  • 13

1 Answers1

2

Problem solved! This article for surprisingly hard to find. Essentially, this is the code I used to solve this :

doc = document.getElementById('test').contentDocument;
doc.open();
doc.writeln('<p> Hello! </p>')
doc.close();

The article is : http://softwareas.com/injecting-html-into-an-iframe

Rajiv Nair
  • 187
  • 1
  • 3
  • 13