Select and focus an existing window

I am launching an e-commerce site and I need this popup to work when a customer submits an order. Ideally, popop will appear when the order success page loads, but blocking pop-ups will stop this.

Instead, I generate a pop-up when the user clicks the "confirm order" button, but this obscures the 3DSecure page to which the check is redirected until the order is completed.

To counteract this, I create a pop-up window when the user clicks "confirm order", but instantly reorients the main window; if you want. My plan is to redirect this new window to the order success page.

The problem is that I cannot find a way to get the object for an existing popup so that I can focus on it. if I create a window using window.open(url,windowName,options) , is there a way to link to it from another page? Something along the lines of window.load(windowName) would be ideal.

+4
source share
2 answers

The signature of window.open is as follows.

 var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]); 

MDN notes that

If a window named strWindowName already exists, then strUrl is loaded into the existing window. In this case, the return value of the method is an existing window, and strWindowFeatures is ignored. Providing an empty string for strUrl is a way to get a link to open a window by its name without changing the location of the window.

So this should work for you.

 window.open('', 'windowName', ''); 

According to MDN, whenever a window opens, a link to it is created,

 var windowObjectReference = window.open("http://www.google.com", "popup", "width=500,height=500"); 

You can always download it using this link, for example

 if(windowObjectReference != null || !windowObjectReference.closed) { windowObjectReference .focus(); } 

Strike>

+4
source

This is complicated, but it works in Chrome. First open the window:

 window.open('/test', 'testw', ''); 

Another link (even on another page) opens a "page" in the same window, passing the same window name. JavaScript url (this is more of a hack):

 window.open('javascript:void window.focus()', 'testw', ''); 

http://jsfiddle.net/pimvdb/KeHtp/

+1
source

All Articles