views:

100

answers:

2

Hi, 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 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 the recreates it but keeps it iconized ... Is there a way i can follow to obtain a good result?

Thanks in advance Greetings, c.

A: 

web_form_target is the window name.

if (wf.name !==  web_form_target) {
   // create it
}
Q_the_dreadlocked_ninja
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.
Cris
+1  A: 

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

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