0
function sethtml(a,b)
{
    var x = document.getElementById("canvas_html").contentDocument; x.write(b);
}

This works but I want to replace the content instead of writing to it.

Max0999
  • 354
  • 4
  • 20

1 Answers1

2
x.innerHTML = b;

This will replace entirely the contents of x for ordinary DOM elements. In the case of an iframe, see this question for details on how to clear an iframe. You could then simply use the write method to add your new content.

Community
  • 1
  • 1
Chris Hayes
  • 11,471
  • 4
  • 32
  • 47
  • Ended up with `function sethtml(a,b) { var doc = document.getElementById("canvas_html"); if( doc.document ) { document.test.document.body.innerHTML = ""; //Chrome, IE }else { doc.contentDocument.body.innerHTML = ""; //FireFox } doc.contentDocument.write(b); }` – Max0999 Nov 12 '12 at 16:47