How To Create a Popup Window from Internet Explore

2019-05-06 19:32发布

问题:

I'm using the following to attempt to create a popup in IE 9

function popUp(url) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(url,'" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=520,left = 400,top = 200');");
  return false;
}

This works fine in Chrome, Firefox and Safari - but IE 9 refuses to open a popup - instead opening the url in a new tab. I've disabled the popup blocker in IE9 - but the function above still opens the url in a new tab and not in a popup.

Any suggestions on how to get IE9 to 'popup'?

回答1:

This code seems to work in IE9 (just checked - opens a new window, not a tab):

function popUp(url) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(url,'" + id + "','_blank','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=520,left = 400,top = 200');");
  return false;
}

I think it may have something to do with indicating the window name, which is different from the existing window.



回答2:

when the user has 'Let Internet Explorer decide how pop-ups should be open' which is the default, setting resize=yes will make IE9 open a tab and resize=no will allow the popup. this might be the same with other attributes i haven't tested.