Dynamically create an iframe and attach onload event to it

I have created a iframe dynamicaly and added a src attribute to it. Then i have appended this iframe to body of the page. Know i want to attach an onload event to iframe to read the iframe content. Can somebody suggest how do i do that.

frame = document.createElement('iframe');
frame.setAttribute('src','http://myurl.com');
body.appendChild(frame);
frame.onload = function(){
    alert('hi'); // here i want to read the content in the frame.
}
11
задан Sami 11 December 2012 в 16:29
поделиться