The "obj.onload=" contruct should override the first onload statement. In Firefox it works fine and when I click the button a "yes" message is shown. But in Internet Explorer the "no" message is shown. My problem is that I need to set the function (anonmymous) that should be called by the brower when iframe.onload and I can't get this to workin in IE. Can anyone help?
Why english?
The problem with here is that IE adds the event listener defined inline internally instead of setting as an attribute for the DOM object. Unfortunately there's no way around this problem when using an inline onload handler. You could either store a variable, or use javascript to attach both handlers. I'd recommened the latter.
<html>
<head>
</head>
<body>
<iframe id="olaf" name="olaf" ></iframe>
<script type="text/javascript">
document.getElementById('olaf').onload = function() { alert('no'); }
</script>
<br />
<input type="submit" onclick="document.getElementById('olaf').src = 'phpinfo.php'" value="Test" />
</body>
<script type="text/javascript">
// Add a bit of randomness to show that the concept works.
if (Math.random()>.5)
document.getElementById('olaf').onload = function() { alert('yes'); }
</script>
</html>
256 ms totalt · 4 externa anrop · v20260731065814-full.1dc6f849