Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Assigning event handling functions for newly opened window

    Hello,

    I've been experiencing strange results from a function that's supposed to open a new window and assign some eventhandling functions to it:

    Code:
    <script> 
    function openTraceWindow() {
        var traceWin = window.open(
            "formTest.html", 
            "trace", 
            "height=480,width=600,resizable=yes" 
        );
        
        traceWin.focus();
        
        //  try to assign unload event handler
        traceWin.onunload = function() {
            alert("I've been unloaded");
        }
        
        //  try to assign resize event handler
        traceWin.onresize = function() {
            alert("I've been resized");
        }
        
        //  try to assign blur event handler
        traceWin.onblur = function() {
            alert("I've been blurred");
        } 
    } 
    
    window.onload = openTraceWindow;
    </script>
    The contents of each anonymous function is just an arbitrary piece of code to alert me if the event takes place, i.e. if the event handling has been successfully assigned.
    formTest.html contains just an ordinary HTML page with no JavaScript inside.

    What I get is the following:
    In IE5.5, nothing happens at all. The window is opened correctly with the page displayed correctly. Only that no alert takes place whether I resize, blur or unload/close the window.

    In Mozilla 1.0, things are even more strange. After opening the new window, the onresize event is triggered -> I see "I've been resized" in the alert dialogue. After clicking ok, another alert with "I've been blurred" appears. So that event has also been triggered. This alert appears twice, so when I click ok on the first, it still appears. Then the "I've been unloaded" appears, and after clicking OK the alert dialogue disappears, but no further blurring/resizing/unloading can fire the events and the registered event handling functions.

    Basically I just want to assign these eventhandling functions from the opening window. I know it can be worked around by doing all this event stuff directly in the opening window, but since I plan to construct its contents entirely through JS, I wanted to dismiss this approach.

    Anybody know what's going in here and can provide some advice to this? Thanks.

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    Portugal
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try to assign the events to the body..

    traceWin.document.body.onunload = function() {
    alert("I've been unloaded");
    }

    this should work..
    You don't want to know...

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your answer, unfortuanetely things aren't improving: IE5.5 comes up with an error message: "document.body is null or not an object", whereas Mozilla throws no error, but doesn't seem to assign an eventhandler properly, since I can close the window or load other content into it without firing the alert...

    The IE5.5 case seems to be connected to the loading state of the child window's document - since it's not loaded completely, it can't have something assigned to it. At least that's my current explanation.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •