Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 5 of 5

Thread: Javascript Error message on Window load

  1. #1

    Javascript Error message on Window load

    Can someone help me with this script? The error message I'm getting when the popup is created: oxygenForm is not defined. The script controls two popup windows and adds a window close event.

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    function newWindow(URL) {
         windowName = "elementForm";
        
        width = 500;
        height = 510;
        scrolling = 0;
        
        var topX = (window.screen.width / 2) - ( width / 2);
        var topY = (window.screen.height / 2) - ( height / 2);
        
        popupWindow=window.open(URL, windowName, 'width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
        // If the browser supports the focus() method place focus on the new window
        if (window.focus) { popupWindow.focus() }
        // If the Oxygen popup is visible then close it
        oxygenForm.close();
    }
    function oxygenPopup(URL) {
         windowName = "oxygenForm";
        
        width = 500;
        height = 760;
        scrolling = 0;
        
        var topX = (window.screen.width / 2) - ( width / 2);
        var topY = (window.screen.height / 2) - ( height / 2);
        
        oxygenWin=window.open(URL, windowName, 'width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
        //If the browser supports the focus() method place focus on the new window
        if (window.focus) { oxygenPopup.focus() }
    }
    //-->
    </script>

  2. #2
    actionAction's Avatar
    1,142
    posts
    humanBeing._beard=true;
    oxygenForm is localized to the function calling it, in your newWindow() function, it should be popupWindow.close(), not oxygenForm.close()

  3. #3
    I forgot to mention that I want to close the window named "oxygenForm" when the "elementChoice" popup is created. In other words, we don't want both popups visible at the same time. The question is: how do we close the other popup? This code actually does work in IE and Firefox (at least on Windows), but it generates an error, of course.

  4. #4
    actionAction's Avatar
    1,142
    posts
    humanBeing._beard=true;
    Yes, but the window's name is not oxygenForm, it is oxygenWin. This statement makes that so:
    Code:
     oxygenWin=window.open(URL, windowName, 'width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
    From the code you have provided, you only have two window objects you are instantiating, popupWindow & oxygenWin. To test if they are open and close it if it is, just use this:
    Code:
    if (windowVariable) { windowVariable.close(); }
    So, delocalize your window objects and you can check to see if they are open in your different functions. BTW, if it generates an error, you shouldn't assume it works (just b/c a browser accepts the error), it probably won't work in the future.

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    var oxygenWin;
    var popupWindow;
    
    function newWindow(URL) {
         windowName = "elementForm";
        
        width = 500;
        height = 510;
        scrolling = 0;
        
        var topX = (window.screen.width / 2) - ( width / 2);
        var topY = (window.screen.height / 2) - ( height / 2);
        
        popupWindow=window.open(URL, windowName, 'width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
        // If the browser supports the focus() method place focus on the new window
        if (window.focus) { popupWindow.focus() }
        // If the Oxygen popup is visible then close it
        if(oxygenWin){ oxygenWin.close(); }
    }
    function oxygenPopup(URL) {
         windowName = "oxygenForm";
        
        width = 500;
        height = 760;
        scrolling = 0;
        
        var topX = (window.screen.width / 2) - ( width / 2);
        var topY = (window.screen.height / 2) - ( height / 2);
        
        oxygenWin=window.open(URL, windowName, 'width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
        //If the browser supports the focus() method place focus on the new window
        if (window.focus) { oxygenPopup.focus(); }
        // If the popupWindow is visible then close it
        if (popupWindow) { popupWindow.close(); }
    }
    //-->
    </script>

  5. #5
    Thanks. I see what you are doing here and it makes sense. I found one glitch in the naming of a window. I believe the code should now read:

    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    var oxygenWin;
    var popupWindow;
    
    function newWindow(URL) {
         windowName = "elementForm";
        
        width = 500;
        height = 510;
        scrolling = 0;
        
        var topX = (window.screen.width / 2) - ( width / 2);
        var topY = (window.screen.height / 2) - ( height / 2);
        
        popupWindow=window.open(URL, windowName, 'width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
        // If the browser supports the focus() method place focus on the
        if (window.focus) { popupWindow.focus() }
        // If the Oxygen popup is visible then close it
        if(oxygenWin){ oxygenWin.close(); }
    }
    function oxygenPopup(URL) {
         windowName = "oxygenForm";
        
        width = 500;
        height = 760;
        scrolling = 0;
        
        var topX = (window.screen.width / 2) - ( width / 2);
        var topY = (window.screen.height / 2) - ( height / 2);
        
        oxygenWin=window.open(URL, windowName, 'width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
        //If the browser supports the focus() method place focus on the new
        if (window.focus) { oxygenWin.focus(); }
        // If the popupWindow is visible then close it
        if (popupWindow) { popupWindow.close(); }
    }
    //-->
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012