5

I have a web app that launches an URL in other windows/tabs. I would like to check if the window/tab exists. If not, I want to create it, else I would like to pick it in the first position. I use:

wf=window.open(address, web_form_target, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=640,height=450');
if(wf!=null)
 wf.focus();
 

But it goes well only the first time (in IE, not in Firefox). If I create a new tab in the window, when I call window.open() nothing happens. If I close the window it recreates it but keeps it ionized.
Is there a way I can follow to obtain a good result?

Thanks in advance.

iknow
10.3k15 gold badges47 silver badges81 bronze badges
asked Oct 14, 2010 at 8:01

2 Answers 2

2
+50

Here's some code I've used for ages that still works as far as I know. Notice that oWindow has global scope, and that I pass it to the second parameter of open as a string, not as the object itself. Then, I test to see if it's closed before trying to open again...if it's already opened, then I just give it focus:

var oWindow;
function openWindow(p_strURL) {
 if(!oWindow || oWindow.closed) {
 oWindow = window.open(p_strURL, "oWindow", "status, scrollbars, resizable, width=800, height=500");
 if(!oWindow.opener) {
 oWindow.opener = window;
 }
 }
 else {
 oWindow.location.href = p_strURL;
 oWindow.focus();
 }
}

Hope it helps you find a solution,

Kevin

answered Oct 20, 2010 at 21:51
Sign up to request clarification or add additional context in comments.

1 Comment

Cool, my friend, this is a big step onward for me. +50 for you !!
0

web_form_target is the window name.

if (wf.name !== web_form_target) {
 // create it
}
answered Oct 14, 2010 at 8:21

1 Comment

i've tried it, but if i open a new tab in the same window of the opened browser, the call to the window fails.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.