在页面加载时打开一个新窗口并激活

时间:2013-05-16 01:25:29

标签: asp.net popupwindow

我试图在页面加载时打开一个新的弹出窗口,并且新窗口已成功打开,但新窗口在主页面的页面后面打开。我想在主页面前激活新窗口。代码在代码隐藏中,如下所示:

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

1 个答案:

答案 0 :(得分: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

如果这不起作用 - 主页面中的其他内容正在接管。您可以尝试在setTimeout块中放置open / focus(顺便说一句,您不必自己添加脚本标记,只需将最后一个参数传递给RegisterStartupScript 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
相关问题