如何在代码隐藏的新窗口或选项卡中打开页面

时间:2022-08-25 23:02:27

So I have a webapplication where I select a value from a dropdownlist. When this value is selected, I want to load another page in a new window.

所以我有一个webapplication,我从下拉列表中选择一个值。选择此值后,我想在新窗口中加载另一个页面。

I tried this:

我试过这个:

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('Default.aspx', '_blank');", true);

It does open the page, but not in a new window/tab. It opens it in the current opened page.

它确实打开了页面,但没有在新窗口/选项卡中打开。它在当前打开的页面中打开它。

Alternatively I tried:

或者我试过:

ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>openDashboardPage()</script>");

and

HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>window.open('Default.aspx', '_new');</SCRIPT>");

They all behave in the same fashion. I just loads the page in the existing window. I tried it in both Firefox and Chrome, thinking it might be a browser thing, but they both behaved the same.

他们都以同样的方式行事。我只是在现有窗口中加载页面。我在Firefox和Chrome中都试过它,认为它可能是一个浏览器,但它们都表现得一样。

How do I open a new window?

如何打开新窗口?

5 个解决方案

#1


17  

Try this one

试试这个

string redirect = "<script>window.open('http://www.google.com');</script>"; 
Response.Write(redirect);

#2


2  

This code works for me:

这段代码适合我:

Dim script As String = "<script type=""text/javascript"">window.open('" & URL.ToString & "');</script>"
ClientScript.RegisterStartupScript(Me.GetType, "openWindow", script)

#3


1  

Use:

使用:

Target= "_blank" property of anchor tag

Target =锚点标签的“_blank”属性

#4


0  

Target= "_blank"

This does it in html, give it a try in C#

这是用html做的,在C#中尝试一下

#5


-1  

You can use scriptmanager.registerstartupscript to call a JavaScript function.

您可以使用scriptmanager.registerstartupscript来调用JavaScript函数。

Inside that function, you can open a new window.

在该功能内,您可以打开一个新窗口。

#1


17  

Try this one

试试这个

string redirect = "<script>window.open('http://www.google.com');</script>"; 
Response.Write(redirect);

#2


2  

This code works for me:

这段代码适合我:

Dim script As String = "<script type=""text/javascript"">window.open('" & URL.ToString & "');</script>"
ClientScript.RegisterStartupScript(Me.GetType, "openWindow", script)

#3


1  

Use:

使用:

Target= "_blank" property of anchor tag

Target =锚点标签的“_blank”属性

#4


0  

Target= "_blank"

This does it in html, give it a try in C#

这是用html做的,在C#中尝试一下

#5


-1  

You can use scriptmanager.registerstartupscript to call a JavaScript function.

您可以使用scriptmanager.registerstartupscript来调用JavaScript函数。

Inside that function, you can open a new window.

在该功能内,您可以打开一个新窗口。