Javascript 如何使用javascript在后台打开弹出窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6842892/
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-08-23 23:25:14  来源:igfitidea点击:

How to open popup windows in background using javascript?

javascriptjquery

提问by prabu

Is it possible to open pop-up windows BEHIND the current active screen using java script?

是否可以使用 java 脚本在当前活动屏幕后面打开弹出窗口?

 var win= window.open(value,'_blank');

the above script opens pop windows in browser tab but I loss active page from my sight.

上面的脚本在浏览器选项卡中打开弹出窗口,但我从视线中丢失了活动页面。

any suggestion?

有什么建议吗?

Thanks in advance

提前致谢

Solution:

解决方案:

As per @Brianadvised,

根据@Brian 的建议,

var win=window.open(value,null,"height=400,width=600,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no");
win.blur();

Its works in IE,FireFox and safari but not in Chrome browser.

它适用于 IE、FireFox 和 safari,但不适用于 Chrome 浏览器

Can any one suggest how to open multiple popup boxes in IE browser?The above script will open only one pop up in IE.

任何人都可以建议如何在 IE 浏览器中打开多个弹出框?上面的脚本只会在 IE 中打开一个弹出窗口。

回答by Brian

You can add:

你可以加:

win.blur();

... to your code ...

...到您的代码...

Or

或者

this.window.focus();

回答by nickf

+1 to Brian's answer to refocus the original window afterwards. If you, for some reason, alwayswant it to be behind, you can use the alwaysLoweredproperty:

+1 对 Brian 的回答以在之后重新聚焦原始窗口。如果您出于某种原因总是希望它落后,您可以使用该alwaysLowered属性:

alwaysLowered
If set to yes, the new created window floats below, under its own parent when the parent window is not minimized. alwaysLowered windows are often referred as pop-under windows. The alwaysLowered window can not be on top of the parent but the parent window can be minimized. In NS 6.x, the alwaysLowered window has no minimize system command icon and no restore/maximize system command.

alwaysLowered
如果设置为 yes,当父窗口未最小化时,新创建的窗口浮动在其自己的父窗口下方。alwaysLowered 窗口通常被称为弹出窗口。alwaysLowered 窗口不能位于父窗口之上,但可以最小化父窗口。在 NS 6.x 中,alwaysLowered 窗口没有最小化系统命令图标,也没有恢复/最大化系统命令。

Good documentation of all the available features can be found on the MDC window.openpage.

可以在 MDC window.open页面上找到所有可用功能的良好文档。

回答by Liam

I found that with Firefox it was not possible to push the window to the back, no matter how much of the code I modified. Ultimately I settled for making the window small enough 10, 10 so that it appeared in one of the corners and was barely perceived by the visitor.

我发现使用 Firefox 时,无论我修改了多少代码,都不可能将窗口推到后面。最终,我决定将窗口缩小到足够小 10、10,这样它就会出现在一个角落里,而访客几乎看不到它。

var win=window.open(value,null,"height=10,width=10,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no");

Chrome opens the popup/under in a tab and iE does place it in the background, behind the active window.

Chrome 在选项卡中打开弹出窗口/下方,而 iE 确实将其放置在活动窗口后面的背景中。

回答by jibiel

For more cross-browser solutionI'd suggest to take a look at this script — jquery-popunder:

有关更多跨浏览器解决方案,我建议查看此脚本 — jquery-popunder

...was tested with:

  • Mozilla Firefox 3-19
  • Google Chrome 10-25
    • Note: Currently you can only create 2 popunder in Chrome 22-24
    • Note: In Chrome 23-24 you'll need a separate event for the popunder-effect (see the examples!)
  • Microsoft Internet Explorer 6-9
  • Apple Safari 5

    Known issues:

  • the script does not work with the Opera-Browser, so the opera-browser is disable by default
  • the script does not work in Firefox under Gnome
  • in Firefox, when the setting: 'Open new windows in a new tab instead' is deactivated

...经过测试:

  • 火狐浏览器 3-19
  • 谷歌浏览器 10-25
    • 注意:目前您只能在 Chrome 22-24 中创建 2 个弹出窗口
    • 注意:在 Chrome 23-24 中,您需要一个单独的 popunder-effect 事件(参见示例!)
  • 微软 Internet Explorer 6-9
  • 苹果 Safari 5

    已知的问题:

  • 该脚本不适用于 Opera 浏览器,因此默认情况下禁用 Opera 浏览器
  • 该脚本在 Gnome 下的 Firefox 中不起作用
  • 在 Firefox 中,当设置:“在新标签页中打开新窗口”被停用时

Note that

注意

This script will only work, if the popunder is opened on a user-generated event (e.g. click or submit).

只有当弹出窗口在用户生成的事件(例如单击或提交)上打开时,此脚本才会起作用。