javascript 如何从 Internet Explorer 9 创建弹出窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6464980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 20:47:07  来源:igfitidea点击:

How To Create a Popup Window from Internet Explorer 9

javascriptinternet-explorer

提问by Blue Waters

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

我正在使用以下内容尝试在 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.

这在 Chrome、Firefox 和 Safari 中运行良好 - 但 IE 9 拒绝打开弹出窗口 - 而是在新选项卡中打开 url。我在 IE9 中禁用了弹出窗口阻止程序 - 但上面的功能仍然在新选项卡中而不是在弹出窗口中打开 url。

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

关于如何让 IE9“弹出”的任何建议?

回答by Aleks G

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

这段代码似乎在 IE9 中工作(刚刚检查 - 打开一个新窗口,而不是一个选项卡):

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.

我认为可能与指示窗口名称有关,与现有窗口不同。

回答by Wayne

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.

当用户有“让 Internet Explorer 决定如何打开弹出窗口”这是默认设置时,设置 resize=yes 将使 IE9 打开一个选项卡,而 resize=no 将允许弹出窗口。这可能与我尚未测试的其他属性相同。