我有一个侧面导航栏,当您单击链接时,它会提交一个表单。表单操作打开另一个页面(target _blank)。我的问题是我必须在这个空白页面打开之前打开一个弹出窗口,并保持它打开足够长的时间,以便用户阅读它,或者至少先看到它,然后根据需要关闭它。我创建了一个在链接的 onclick 事件上打开弹出窗口的函数。看起来像这样:
<li><a href="JavaScript:document.quoteform.submit()" onclick="popUp('ag_popup.html')">Submit a Deal</a></li>
我的函数如下所示:
function popUp(url)
{
leftPos = 0
topPos = 0
if (screen) {
leftPos = (screen.width / 2) - 150
topPos = (screen.height / 2) - 250
}
newwindow=window.open(url,'name','height=300,width=500,left='+leftPos+',top='+topPos);
if (window.focus) {newwindow.focus()}
return false;}
有谁知道我是否可以保持弹出窗口打开并聚焦,而不在其前面打开新的空白页面?
干杯
最佳答案
您可以使用setTimeout - 等待的功能,将引用保留在弹出窗口上,然后关闭它(或让用户决定!)。之后从该函数提交表单。
例如:
var newWindow=null;
function popUp(url)
{
leftPos = 0
topPos = 0
if (screen) {
leftPos = (screen.width / 2) - 150
topPos = (screen.height / 2) - 250
}
newWindow=window.open(url,'name','height=300,width=500,left='+leftPos+',top='+topPos);
if (window.focus) {newWindow.focus()}
setTimeout('closePopupAndSubmit()')', 5000);
}
function closePopupAndSubmit{
if(newWindow != null){
newWindow.close();
document.quoteform.submit();
}
}
关于javascript - 我可以设置弹出窗口获得焦点的时间长度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2908098/