1

I have a scenario where I need to open multiple popup almost 5 . If I use window.open() method , I can open multiple popups but it is not staying on top of parent page all the time. After I open first popup , it shows on top of parent page. then when I access parent page to open second popup , first popup goes behind the parent page. Is there any way I can achieve this functionality.

Any help greatly appreciated

Mey
  • 25
  • 7

1 Answers1

0

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;            
}
Community
  • 1
  • 1
Baga
  • 1,354
  • 13
  • 24
  • Thanks for the reply. But popupWindowsArr not retaining the popup windows when the page post back.So always it opens the current popup window not all – Mey Aug 18 '14 at 13:55
  • Yes. It is very useful. I will try to find out a way for chrome. Because most of our users use chrome. If you find anything, let me know. – Mey Aug 18 '14 at 15:21
  • @Mey Sure, will see if I can find anything. If this answer was helpful, pls accept it. – Baga Aug 18 '14 at 15:30