To load an doc inside a iframe dynamically

We can load a document into an iframe dynamically by using iframe.src = “yourpage” in javascript.
But this works well in IE and not in others browsers. Here is an method to load iframes dynamically.

I found this at and just changed something to fit our need.

var IFrameObj;
function loadIFrame(thePage){
//loads an doc inside a iframe dynamically
URL = thePage;
IFrameObj = new Object();
IFrameObj.document = new Object();
IFrameObj.document.location = new Object();
IFrameObj.document.location.iframe = document.getElementById('cpaneif');
IFrameObj.document.location.replace = function(location) {
this.iframe.src = location;

if (navigator.userAgent.indexOf(‘Gecko’) !=-1 && !IFrameObj.contentDocument) {
// allow a fraction of a second to recognize the new IFrame
//return false;

if (IFrameObj.contentDocument) {
// For NS6
IFrameDoc = IFrameObj.contentDocument;
} else if (IFrameObj.contentWindow) {
// For IE5.5 and IE6
IFrameDoc = IFrameObj.contentWindow.document;
} else if (IFrameObj.document) {
// For IE5
IFrameDoc = IFrameObj.document;
} else {
return true;

/* NB:-
//if you want to create a new iframe dynamically visit

The ‘alt’ property does not work with mozilla/firefox

The correct property to use for tooltips is title. The ‘alt’ property has a very important purpose, which is to provide replacement text for images in browsers that cannot or do not (by user’s choice) display images, and if graphical browsers display them as tooltips people will be discouraged from using them for their correct purpose.

for more info