tags:

views:

50

answers:

2

I have an application that opens a new window on clicking a button.

There are many buttons to open multiple windows if the windows don't already exist.

All the buttons and url are dynamic, therefore, I use a function to open window with the following codes:

function openwin(url, winname)
{   
    var winRef = window[winname];

    if( typeof winRef =='undefined' || winRef.closed)
    {    
        winRef = window.open (url, 'winname');
        winRef.focus();
    }
}

But there is problem/bug:

When I click on button A, it opens new window A.
When I click on button B, it "overwrite A" and the window become B.
When I click on button A again, it "overwrite B" and the window become A.

Therefore, I always open one new window.

+1  A: 
winRef = window.open (url, 'winname');

should probably be

window[winname] = window.open (url, winname);
epascarello
A: 

Thanks. But the above code can't solve my bug.