开发者

JavaScript Pop Up Issue

This happens in IE only (works in Chrome, Firefox):

The first time I click on the link, it opens the pop up, the second time, it just redire开发者_Python百科cts me to the page.

When I refresh the page, the popup works the first time and then the second time, it again redirects.

function popUpWindow(win) {
  myWindow = window.open(win, "popupwin", "height=310,width=570,resizeable=0, menubar=0,toolbar=0,location=0, directories=0,status=0");
}

This is how I call the function

 <a href="#" onclick="popUpWindow('/usere.htm'); return false;">User Status</a>

EDIT: I apologize, the second time, it does not redirect, nothing happens when i click on the link It is redirecting.

EDIT: I close the popup when it opens up the first time and then click the popup link again.

I tried all the solutions presented below, what I found is that the JavaScript method is not called the second time I click on the link.


If the issue is that the popup is being redirected the second time, this is correct behavior according to the code. The name parameter is specified so that a popup can be reused. I don't necessarily recommend this, but you could use this to open multiple popups:

var popupIndex = 0;
function popUpWindow(win) {
  myWindow = window.open(win, "popupwin" + popupIndex++, "height=310,width=570,resizeable=0, menubar=0,toolbar=0,location=0, directories=0,status=0");
}


Check whether the window has already been opened or been opened and subsequently closed. The following will focus the pop-up if it exists or open a pop-up otherwise. It's not clear whether you always want a new pop-up or whether focussing an existing one is good enough.

var myWindow = null;

function popUpWindow(win) {
  if (!myWindow || myWindow.closed) {
    myWindow = window.open(win, "popupwin", "height=310,width=570,resizeable=0, menubar=0,toolbar=0,location=0, directories=0,status=0");
  } else {
    myWindow.focus();
  }
}

If you always want to close an existing pop-up before opening a new one:

var myWindow = null;

function popUpWindow(win) {
  if (myWindow && !myWindow.closed) {
    myWindow.close();
  }
  myWindow = window.open(win, "popupwin", "height=310,width=570,resizeable=0, menubar=0,toolbar=0,location=0, directories=0,status=0");
}


I assume you want to refresh the window which you would do like this:

var myWindow = null;
function popUpWindow(win) {
    if (myWindow && !myWindow.closed) {
        myWindow.close();  
    }
    myWindow = window.open(win, name, options);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜