Loading Multiple Documents into the Same Pop Up Window
When you want to use one generic function to open multiple documents into the same pop-up window, replace the open method's file name parameter with an argument. The argument, which will be the file name, is defined when you call the function. Every time the function is called, a different file name can be passed back, hense loading a different file into the window for each function call. Because the new windows have the same name (win1), only one new window is created. Now one function can be used to open any number of pages in your new window.
function popUp(URL){
pop = window.open(URL,"win1","width=400,height=500,resizable=1,scrollbars=1")
pop.focus()
}
Changing Window Properties on the fly
If you need to change the
properties (width,scrollbars,top, etc.) of a window for each new document, the function gets slightly more complex. NN 4.x has no problem allowing you to change properties on the fly, but MSIE will not allow you to change window properties. Because of this, your function needs to close the pop up window (if it is open) first, then re-open it with its changed properties.
Try clicking on the following links consecutively
without closing the window they launch.
width=100,height=100,location=0,status=0
width=500,height=500,location=1,status=0
width=500,height=250,location=1,status=1
When you need flexibility in terms of changing window properties with each call to the function, add the following lines:
var pop //create global variable without assigning a value so that its value is null
function popUp(URL,w,h){
if(pop!=null && !pop.closed){ // if popUp has been opened, and popUp hasn't already been closed
pop.close() //close it in order to re-assign properties
}
pop = window.open(URL,"win1","width="+w+",height="+h+",resizable=1,scrollbars=1")
pop.focus()
}
First pop is initialized as a global variable (a variable outside a function) and not assigned a value so that its value is null. When the function is invoked, pop is given a value just by assigning the open method to it. So, if the function has been invoked, its value will NOT be null. The if statement checks its value to see if it has ever been opened. It also checked to see if it has not been closed yet. If both of those checks evaluate to true, the window is closed before being re-opened again, making the properties changable.
Check the status of the variable, "pop" once before the function has executed, then after.
View the Source