read

This is the kind of problem you spends more time testing through browsers rather than implementing itself.

And the solution is pretty simple, a single for all browsers family.

// Create a HTMLIFrameElement.
var iframe = document.createElement("IFRAME");

// IE: frameBorder must be changed before
// calling #appendChild method.
iframe.frameBorder = 0;
iframe.width = 200;
iframe.height = 200;
document.body.appendChild(iframe);

// Write into the iframe document.
iframe.contentWindow.document.open();
iframe.contentWindow.document.write("Write any content here!");
iframe.contentWindow.document.close();

Browser support:

  • IE 5.5+
  • Firefox 2.0+
  • Chrome 1.0+
  • Safari 3.1+

Living example

Dynamic iframe contents

Blog Logo

Endel Dreyer

Full-stack developer. Loves Ruby and JavaScript.


Published

Image

bugfixer / @endel

About programming, tools and solving problems.

Back to Overview