Hi,
I have an iframe in my HTML, and I want to be notified when it's fully loaded. I have this testcase:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Test</title>
<script language="javascript" type="text/javascript">
function addListener(el, type, func, capture) {
if (el.addEventListener){
el.addEventListener(type, func, capture);
} else if (el.attachEvent){
el.attachEvent('on'+type, func);
}
}
function addhandlers(frame) {
addListener(frame, "load", function(e) { onDomLoaded(e); }, true);
}
function onDomLoaded(e) {
alert("loaded");
}
</script>
</head>
<body>
<form action="#">
<input type="button" value="Add handlers" onclick="addhandlers(window.frames[0]);" />
</form>
<iframe id="frm" height="300" src="test.htm" width="700"></iframe>
</body>
</html>
The test.htm file is just a standard html file with a few regular links to places.
First I click the Add Handlers button to add the listeners, then I click any link in test.htm inside the iframe. My expectation is that I get an alert, but nothing happens. Why, and how do I solve it? I'm currently looking for a solution that works in firefox and IE (but nothing happens in either browser).