当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Allow multiple windows to be opened if the windows don't already exist

问题描述:

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.

网友答案:
winRef = window.open (url, 'winname');

should probably be

window[winname] = window.open (url, winname);
分享给朋友:
您可能感兴趣的文章:
随机阅读: