---
title: "ifram onload IE problem"
type: "forum-thread"
url: "https://www.webforum.nu/amne/javascript/148872-ifram-onload-ie-problem"
topic: "JavaScript"
topic_url: "https://www.webforum.nu/amne/javascript"
author: "niels"
published: "2006-07-09T19:52:22.000Z"
updated: "2006-07-10T08:14:11.000Z"
replies: 2
views: 383
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/javascript/148872-ifram-onload-ie-problem"
---

# ifram onload IE problem

## #1 — niels, 2006-07-09T19:52Z

Look at the following code:

```
<html>
<head>

</head>
<body>

<iframe id="olaf" name="olaf" onload="alert('no');"></iframe><br>
<input type="submit" onclick="document.getElementById('olaf').src = 'phpinfo.php'" value="Test">

</body>

<script language="javascript">
var obj = document.getElementById('olaf');
obj.onload = function() { alert('yes'); }
</script>

</html>
```

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?

Thanks!
/Niels

Permalänk: https://www.webforum.nu/p/148872

## #2 — yohpops, 2006-07-10T06:32Z

Why do you need to use both "onloads"?
When I use your code in IE I get both messages.

Permalänk: https://www.webforum.nu/p/1838175

## #3 — nitro2k01, 2006-07-10T08:14Z

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>
```

Permalänk: https://www.webforum.nu/p/1838191

---

Tråden på webben: https://www.webforum.nu/amne/javascript/148872-ifram-onload-ie-problem
