Search code examples
javascriptinternet-explorerwindow.open

IE on click of a link opens pop up again and again instead of showing in the same screen


When i click on a link in my application header it should open a pop up screen, but when i click on the same link from someother page it is opening in another pop up even though i had not closed the earlier one. This issue is prevailing only in IE and not in other browsers.

function popUpForInvoice(url) 
{
   var csrfName = document.getElementById("csrf").getAttribute("name");
   var csrfToken = document.getElementById("csrf").value;
   var newUrl = "/ecommerce/mitac/" + url + "&"+ csrfName + "=" + csrfToken;
   var left = (screen.width/2)-(550/2);
   var top = (screen.height/2)-(550/2);
   var  ua = window.navigator.userAgent;
   var msie = ua.indexOf("MSIE");
   if (msie > 0)      
       window.open(newUrl,'_blank','toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=no,width=540,height=600,left ='+left+',top ='+top+'');
else                 
       window.open(newUrl,'about:blank','toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=no,width=540,height=600,left ='+left+',top ='+top+'');
}

Solution

    1. _blank as target is DESIGNED to open a new window each time
    2. about:blank is not a valid target - use something like mywindow to reuse
    3. No need for the agent test which by the way will fail in IE11 anyway.
    4. some of your parameters are not necessary and spaces are not allowed in the parameters

    This should work

    Remove

    var  ua = window.navigator.userAgent;
     var msie = ua.indexOf("MSIE");
     if (msie > 0)      
           window.open(newUrl,'_blank','toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=no,width=540,height=600,left ='+left+',top ='+top+'');
    else                 
    

    And just have

    window.open(newUrl,'mywindow',
     'scrollbars,resizable=no,width=540,height=600,left='+left+',top='+top);
    

    Do note that you will likely need to focus the window or it will stay under when opened the second and subsequent times