1

我试图在页面加载时打开一个新的弹出窗口,新窗口已成功打开,但新窗口是在主页页面后面打开的。我想让新窗口在主页前处于活动状态。该代码在代码隐藏中,如下所示:

If Not IsPostBack Then
   Page.ClientScript.RegisterStartUpScript(me.GetType(),"popup","<script language=javascript>window.open('WebForm2.aspx','','width=300px,height=200px')</script>")
End If
4

1 回答 1

3

.focus()在末尾添加window.open

If Not IsPostBack Then
   Page.ClientScript.RegisterStartUpScript(me.GetType(),"popup","<script language=javascript>window.open('WebForm2.aspx','','width=300px,height=200px').focus();</script>")
End If

如果这不起作用 - 主页中的其他内容正在接管。您可以尝试将 open/focus 放在setTimeout块中(顺便说一下,您不必自己添加脚本标签,只需将最后一个参数传递给RegisterStartupScriptas True

If Not IsPostBack Then
   Page.ClientScript.RegisterStartUpScript(me.GetType(),"popup","setTimeout(""window.open('WebForm2.aspx','','width=300px,height=200px').focus();"",1);", True)
End If
于 2013-05-16T01:35:25.827 回答