...

View Full Version : iFrame onload event



mr_ego
12-21-2004, 12:28 PM
When i execute the following code:



document.getElementById ("iframeobj").contentWindow.onload = new function () {
document.getElementById ("iframeobj").contentWindow.applycommand ();
}



the command is executed, but the result is rolledback after the frame has loaded. does anyone have any ideas? i'm aware of the restrictions that the iframe property has, but i don't think this is affected by this, is it?


Using: MIRCOSOFT INTERNET EXPLORER 6.0
O/S: Microsoft Windows XP (SP1)


I've attached two files to show an example, but i've renamed them to .txt. just remove the extension and it should work.

Willy Duitt
12-21-2004, 06:20 PM
I do not think you are using contentWindow properly...
When I run your script I get an unspecified error #84...

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/contentwindow.asp

.....Willy

mr_ego
12-22-2004, 02:13 AM
so how do i force an iFrame to run a command remotely (keeping in mind the files are on the same domain)

glenngv
12-22-2004, 02:19 AM
<iframe name="panel[frame]" src="test2.html" onload="this.contentWindow.applycommand()"></iframe>

mr_ego
12-22-2004, 03:04 AM
Well, my iFrame isn't generated in html, it's generated through a document.createElement command.

Willy Duitt
12-22-2004, 03:25 AM
Well, create the onload attribute when you create the element...

mr_ego
12-22-2004, 12:55 PM
doesn't work




function createTheElement () {
var iframe = document.createElement ("IFRAME");
iframe.frameBorder = 1;
iframe.width = 400;
iframe.height = 400;
iframe.src = "test.html";
iframe.setAttribute ("id", "testframe");

iframe.onload = new function () {
alert (document.getElementById ("testframe").style);
}

document.getElementById ("testit").innerHTML = iframe.outerHTML;
}

window.onload = new function () {
createTheElement ();
}

Willy Duitt
12-22-2004, 03:53 PM
What doesn't work?? Creating the onload attribute and firing the alert certainly does, but what is this??

alert (document.getElementById ("testframe").style);

.....Willy

mr_ego
12-23-2004, 05:26 AM
can someone please upload an example?!

glenngv
01-03-2005, 06:32 AM
IE only:


function createTheElement () {
var iframe = document.createElement ('<iframe onload="this.contentWindow.applycommand()"></iframe>');
iframe.frameBorder = 1;
iframe.width = 400;
iframe.height = 400;
iframe.src = "test.html";
iframe.setAttribute ("id", "testframe");
document.getElementById ("testit").innerHTML = iframe.outerHTML;
}

window.onload = function () {
createTheElement ();
}

mr_ego
01-03-2005, 07:24 AM
that isn't really good w3c standard ... besides it has to work for FireFox aswell.

glenngv
01-03-2005, 03:15 PM
I assumed you want it to work with IE only because you use outerHTML. Use appendChild instead of innerHTML/outerHTML.

Try this:


function createTheElement() {
var iframe;
if (document.all){
iframe = document.createElement('<iframe onload="alert(document.getElementById (\'testframe\'))"></iframe>');
}
else if (document.getElementById) {
iframe = document.createElement('iframe');
iframe.onload=function(){alert(document.getElementById('testframe'))};
}
if (!iframe) return;
iframe.frameBorder = 1;
iframe.width = 400;
iframe.height = 400;
iframe.src = "test2.html"
iframe.setAttribute ("id", "testframe");
document.getElementById ("testit").appendChild(iframe);
}

window.onload = function () {
createTheElement ();
}

mr_ego
01-04-2005, 12:37 AM
Ahh i'm such a dimwit! Thanks for that glenngv. Is it possible that you can get the help member of the millenium award?

glenngv
01-07-2005, 03:26 AM
Ahh i'm such a dimwit! Thanks for that glenngv. Is it possible that you can get the help member of the millenium award?
There's a new Nominate a helpful member thread. :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum