JavaScript to Load Iframes

There are three ways to load a new document into an iframe using JavaScript as described in Loading New Documents into Iframes:

function setIframeSrc(id, url) {
    document.getElementById(id).src = url;

function setIframeLoc(nm, url) {
    window.frames[nm].location = url;

function replaceIframeURL(nm, url) {

Generally, these would be called from within JavaScript, but you can also call them from links. The following demonstrates an example link:

<a href="code.html" target="ifrm" 
    onclick="setIframeSrc('ifrm', this.href); return false">Code</a>

If you want to use one of the other functions instead, substitute its name in the onclick attribute.