View Full Version : Javascript DOM Iframe Onload

07-11-2007, 10: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>';

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?

07-11-2007, 11: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">
<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.onload = function()

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