Asp tutorial. net Response. Redirect jump out of framework and window opening method
Js top. location is probably used to jump out of the framework.
Response. Write ('<script> top. location = 'http: // www.111cn.net'; </script> ');
Response. the Redirect Method is switched on the server side, so unless Response. write ("<script> window. location = 'URL'; </script> ") the specified url address cannot be opened in a new window. However, if you carefully analyze it and set the target attribute of the form element, you can still open the new window
<% @ Page Language = "C #" AutoEventWireup = "true" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<Script runat = "server">
Protected void Page_Load (object sender, EventArgs e)
{
Button1.Attributes. Add ("onclick", "this.form.tar get = '_ newname '");
}
Protected void button#click (object sender, EventArgs e)
{
Response. Redirect ("http://dotnet.aspx.cc ");
}
</Script>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> </title>
</Head>
<Body id = "B" runat = "server">
<Form id = "form1" runat = "server">
<Asp: Button ID = "Button1" runat = "server" OnClick = "button#click" Text = "open a new window or new Tab"/>
</Form>
</Body>
</Html>
To set the width and height of the pop-up window, you can change it to the following method:
<% @ Page Language = "C #" AutoEventWireup = "true" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<Script runat = "server">
Protected void Page_Load (object sender, EventArgs e)
{
String WindowName = "win" + System. DateTime. Now. Ticks. ToString ();
Page. RegisterOnSubmitStatement ("js", "window. open ('', '"+ WindowName +"', 'width = 600, height = 200 ')");
Form1.Target = WindowName;
}
Protected void button#click (object sender, EventArgs e)
{
Response. Redirect ("http://www.111cn.net ");
}
</Script>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> </title>
</Head>
<Body id = "B" runat = "server">
<Form id = "form1" runat = "server">
<Asp: Button ID = "Button1" runat = "server" OnClick = "button#click" Text = "open a new window or new Tab"/>
</Form>
</Body>
</Html>