...

View Full Version : Javascript DOM Iframe Onload



JustinMs66
07-11-2007, 09:11 PM
i have successfully dynamically created an iframe object using only javascript. i couldn't get createElement() to work so i ended up just using innerHTML+= and then the actual html code. all in all, it works.


var iframehtml = '<iframe src="http://google.com"></iframe>';
document.getElementById('iframeholder').innerHTML=iframehtml;

now what i want to do is add a onload listener. once the iframe has successfully loaded the url, do something.

how would i go about doing that?

_Aerospace_Eng_
07-11-2007, 10:20 PM
Not sure what you did wrong trying to create the iframe using dom. This code does it just fine. It also has an onload set to the iframe

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
window.onload = function()
{
var createIframe = document.createElement('iframe');
createIframe.setAttribute('src','http://www.google.com');
createIframe.onload = function()
{
alert('hello');
}
document.getElementById('iframeholder').appendChild(createIframe);
}
</script>
</head>

<body>
<div id="iframeholder"></div>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum