One way is to store the window handles in an array and call the focus method. It works in IE. It will not work in Chrome, details here
FIDDLE
Code below.
var popupWindowsArr = new Array();
function popupClicked() {
var title = "Test -" + popupWindowsArr.length;
var wndID = window.open("http://www.google.com", title, "height=400,width=700");
popupWindowsArr.push(wndID);
for(var i = 0; i < popupWindowsArr.length; i++) {
popupWindowsArr[i].focus();
}
}
EDIT - To bring focus to popups after a postback.
One way is store the names of the opened windows in a hidden field and use it. This will work only if the popup url is in the same domain.
<asp:HiddenField ID="hdnPopupNames" runat="server" />
function popupClicked() {
var popupNames = document.getElementById('<%=hdnPopupNames.ClientID %>').value;
var wndName;
if (popupNames.length > 0) {
var namesArr = popupNames.split("|");
wndName = "Test -" + namesArr.length;
for (var i = 0; i < namesArr.length; i++) {
var wnd = window.open("", namesArr[i]);
wnd.focus();
}
popupNames += "|" + wndName;
}
else {
wndName = "Test - 0" ;
popupNames = wndName;
}
window.open("TestHTMLPage.htm", wndName, "height=400,width=700");
document.getElementById('<%=hdnPopupNames.ClientID %>').value = popupNames;
}