0

I guess this might be a duplicate question but the existing answers were not of much help.

So, I have the below function which I have registered for onclick of a link:

function open_new()
{ 
if (win===null)
{
win=window.open("url","_blank");
}
else{
win.location.href="url";
win.focus();}
}

Dont worry much about the logic. In plain words, if user clicks on the link for the first time in the parent window, it open the url in a new window say window 2.

Now here the problem comes up -- > I move back to parent window and again I click on that link. It sets the href of window 2 , reloads it but does not focus. It will still remain on parent window.

Note: This works perfectly in chrome.

Robin
  • 8,162
  • 7
  • 56
  • 101
Vipul Kumar
  • 259
  • 1
  • 2
  • 12

2 Answers2

0

IE8 isn't allowing this feature because of security issues

Check this article

https://support.microsoft.com/en-us/kb/979954

stacker
  • 21
  • 1
  • 6
  • So I guess the same behavior persists in IE9,10,11 .Because in none of them it works. Is there any workaround ??? – Vipul Kumar Nov 05 '15 at 09:59
0

Yes indeed, this seems not to work in IE. Would it be a problem to re-open the window in IE instead? You could make a browser check to do that only in IE or always.

function isIE() /* taken from http://stackoverflow.com/a/20881274/265165 */
{
    var isIE11 = navigator.userAgent.indexOf(".NET CLR") > -1;      
    var isIE11orLess = isIE11 || navigator.appVersion.indexOf("MSIE") != -1;
    return isIE11orLess;
}

var win;
function openWindow() {
    if (win == null) {
        win = window.open("url", "_blank");
    } 
    else if (isIE()) {
        win.close();
        win = window.open("url", "_blank");
    }
    else {
        win.location.href = "url";
        win.focus();
    }
);
thmshd
  • 5,729
  • 3
  • 39
  • 67