使用 Javascript/jQuery 在当前窗口后面打开一个窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11407153/
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
Open a window behind the current window using Javascript/jQuery
提问by Carlos
I want to open a window on click, but I want to open it behind the current window, or when the new window opens it should minimize itself. I have made a function but it actually did not work.
我想在点击时打开一个窗口,但我想在当前窗口后面打开它,或者当新窗口打开时它应该最小化自己。我做了一个函数,但它实际上不起作用。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function wn(){
var mm=window.open('http://www.google.com','newwindow','width=200, height=200', "_blank");
}
</script>
</head>
<body>
<a href="#" onclick="wn()">click</a>
</body>
回答by Pranay Rana
EDIT
编辑
Parent window HTML
父窗口 HTML
<script language="JavaScript" type="text/javascript">
function openPopUP() {
window.open('mywindow.html','NewWin',
'toolbar=no,status=no,width=350,height=135')
}
</script>
<body onLoad="openPopUP();">
or
<a href="javascript:openPopUP();">Click to open popup</a>
Child Window i.e PopUp Window File
子窗口即弹出窗口文件
The below script should be in the child window. The child window will open and will automatically be hidden after 1 second. The value 1000
specified in the setTimeout
method is the duration in milliseconds for which the child window will be open. You can increase this timeout duration if you want the child window to be open longer.
下面的脚本应该在子窗口中。子窗口将打开并在 1 秒后自动隐藏。方法中1000
指定的值setTimeout
是子窗口将打开的持续时间(以毫秒为单位)。如果您希望子窗口打开更长时间,您可以增加此超时持续时间。
<body onLoad="setTimeout('window.blur()', 1000);"
onFocus="setTimeout('window.blur()', 1000);">
This might work for you: Add this line of code in the onload
event of your child window...
这可能对你有用:在onload
你的子窗口的事件中添加这行代码......
window.parent.opener.focus();
回答by odupont
popunder = window.open('http://www.google.com','newwindow','width=200, height=200', "_blank");
popunder.blur();
window.focus();
回答by Rorchackh
Try something like this.
尝试这样的事情。
window.open(url);
self.focus();
回答by NG.
Although it causes security issues, but I guess one of the way to do it is :
虽然它会导致安全问题,但我想其中一种方法是:
popup = window.open('http://www.google.com', 'newwindow', "_blank");
popup.blur();
This will work only in IE. For other browsers you need to set the security level to minimum.
这仅适用于 IE。对于其他浏览器,您需要将安全级别设置为最低。
回答by Hiren Soni
popunder = window.open('your_site_url','newwindow','width=500, height=500', "_blank");
popunder.blur();
window.focus();
or simply
或者干脆
window.open(url); self.focus();
回答by Mike Grace
If you want real popunder capabilities there is a great jQuery plugin to handle it at https://github.com/hpbuniat/jquery-popunder
如果你想要真正的 popunder 功能,有一个很棒的 jQuery 插件可以在https://github.com/hpbuniat/jquery-popunder上处理它
It uses a combination of various techniques to accomplish it across various browsers. Not all browsers can handle it the same but the results are very similar.
它使用各种技术的组合来跨各种浏览器完成它。并非所有浏览器都能以相同的方式处理它,但结果非常相似。
Current browser compatibility is listed as: (last updated April '18)
当前浏览器兼容性列出为:(上次更新时间为 2018 年 4 月)
- Mozilla Firefox 3-57
- Google Chrome 10-62
- Microsoft Internet Explorer 6-11 -- MSIE 6-8 requires jquery 1.x
- Apple Safari 5
- 火狐浏览器 3-57
- 谷歌浏览器 10-62
- Microsoft Internet Explorer 6-11 -- MSIE 6-8 需要 jquery 1.x
- 苹果 Safari 5
回答by Karthik Linga
Finally , it was working for me only in chrome browser. Add this code in Parent window:
最后,它只在 chrome 浏览器中对我有用。在父窗口中添加此代码:
<script type="text/javascript" language="javascript">
function popWindow()
{
var popupo = window.open("popup.html", 'newwindow','toolbar=no,status=no,width=650,height=450', "_blank");
popupo.moveTo(0, 0);
popunder.blur();
window.focus();
}
</script>
Add this code in child window body onload event as
将此代码添加到子窗口主体 onload 事件中
<body onLoad="setTimeout('window.blur()', 1000);" onFocus="setTimeout('window.blur()', 1000);">