John Smitty John Smitty - 1 year ago 89
Javascript Question

Javascript- Open New Window Without Reusing Previously Opened One

So my problem is I have a button on my original page that should open a new window so the user can create a new object. This works fine the first time I press the button. However, if I want to create another object at the same time and press the create new object on my original page, instead of creating another new window, the site just opens the new create object page on the same window of the first new object I was trying to create. Obviously this results in all the information I originally typed to create a new object being lost.

Here is the onClick that calls my openPopWindow function which opens the window.

onClick="openPopupWindow('<% =NEWOBJECT_URL %>', 0);"


Here is the openPopWindow function

function openPopupWindow(strPage, TicketId){
var winTop = 10;
var winLeft = Math.round(screen.width / 2) - 800/2;
var POPUP_FEATURES = "scrollbars=no,resizable=yes,toolbars=no,status=no,height=650,width=800";
POPUP_FEATURES += ",top=" + winTop + ",left=" + winLeft;
var POPUP_NAME = "NewViewWindow"
var POPUP_FNAME = strPage;
var PopupURL, URLParams;
var theWindow

PopupURL = POPUP_FNAME;
theWindow = window.open(PopupURL, POPUP_NAME, POPUP_FEATURES);
theWindow.focus();
return theWindow;
}


So is there a way so that a new window can always be opened instead of reusing the same opened page? Any help is greatly appreciated!

Answer Source

If a window with the name already exists, then strUrl is loaded into the existing window. In this case the return value of the method is the existing window and strWindowFeatures is ignored. Providing an empty string for strUrl is a way to get a reference to an open window by its name without changing the window's location. To open a new window on every call of window.open(), use the special value _blank for strWindowName.

window.open

var POPUP_NAME = "_blank"

also note from the docs that the window name is not the title. To set the title you would do

theWindow.document.title = "NewViewWindow"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download