JavaScript to Load Iframes

There are three ways to load a new document into an iframe using JavaScript. The first uses document.getElementById to reference the iframe element and assigns a new URL to its src property.

var el = document.getElementById('ifrm');
el.src = url;

A second alternative uses the frames array to obtain a reference to the iframe window and assigns the new URL to its location property.

window.frames['ifrm'].location = url;

A third alternative uses the location.replace method in order to avoid having the new URL added to the browser history.

window.frames['ifrm'].location.replace(url);