Results 1 to 5 of 5
-
March 10th, 2008, 04:25 PM #1519Registered User
posts
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>
-
March 10th, 2008, 09:11 PM #2
oxygenForm is localized to the function calling it, in your newWindow() function, it should be popupWindow.close(), not oxygenForm.close()
-
March 10th, 2008, 11:01 PM #3519Registered User
postsI 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.
-
March 11th, 2008, 11:42 AM #4
Yes, but the window's name is not oxygenForm, it is oxygenWin. This statement makes that so:
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:oxygenWin=window.open(URL, windowName, 'width=' + width + ',height=' + height + ',location=no,resizable=yes,scrollbars=' + scrolling + ',screenX=' + topX + ',screenY=' + topY);
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:if (windowVariable) { windowVariable.close(); }
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>
-
March 11th, 2008, 06:50 PM #5519Registered User
postsThanks. 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>

Reply With Quote

Bookmarks