tags:

views:

45

answers:

5

why the following code works in safari but not in IE6 ? It opens the window but doesnt trigger the alert.

    <script>
        function fnOpenChild()
        {
            var openChild = window.open('child.htm');
            openChild.onload = function() { 
            alert("im the child window");
        };
    }

    </script>

<input type="button" onClick="fnOpenChild()">

Thank You

A: 

I know this isn't actually an answer, but I really suggest you don't use IE6 anymore, and just go with IE8+.

Afterwards, add code that will warn the user that he/she is using an out-dated web browser. You can detect the browser version using navigator.appVersion

If you want to know why you or anyone else shouldn't use it anymore:

http://www.google.nl/#hl=nl&amp;source=hp&amp;biw=1024&amp;bih=837&amp;q=Why+IE6+must+die

Edit: Aah, I guess you fixed it, but I still suggest you take a look at the link above. :)

Nick
@nick i have been trying to convince people here[work] to stop using IE6 but no luck and I have been asked to do it in IE6. I have got no choice. and NO I have not fixed it, still no alert box.
manraj82
Aah, too bad.. Well, I guess they will find out sooner or later. Edit: Aah, I see. I thought you said you did, but you were talking about invisible code. :P
Nick
Here here! IE 6 is a blight on the community! (Have you ever tried to deal with z-index on that piece of manure? It's a NIGHTMARE)
Christopher W. Allen-Poole
A: 

IE6 has some... rather interesting issues and it requires some workarounds. Have you tried googleing, "IE6 window onload"? http://www.webdeveloper.com/forum/showthread.php?t=183578 seems to have a working suggestion.

Christopher W. Allen-Poole
+1  A: 

try it! to move onload event to child.htm

Dragoon zhang
@Dragoon i wud have but im thinking of passing values from the parent to child window in that function, so i need that function to work in the parent window
manraj82
@manraj82, please see my answer, it may be helpful for you :)
jerjer
A: 

Try applying onreadystatechange as well. IE6 has some issue with onload.

openChild.onload = openChild.onreadystatechange = function() { ...
Luca Matteis
A: 

There could be two possible work-arounds:

1. Move the onload script ot the childwindow

**child.htm**
<html>
<script type="text/javascript">
    window.onload = function(){
        alert('im the child window');
    }
</script>
<body>
 ....
</body>
</html>

2. Declare a function in the opener window and call it on the the child's onload

**parent.htm**
<script type="text/javascript">
   function forChildWindow(params){
        alert('im the child window' + params);
   }
</script>

**child.htm**
<html>
<script type="text/javascript">
    window.onload = function(){
        var load = window.opener.forChildWindow;
            var someparams = " param1";
        if(load) { 
            load(someparams);
            }
    }
</script>
<body>
 ....
</body>
</html>
jerjer