Use Response.Redirect to open the page in a new browser window
This article describes how to use ASP.NET's Response.Redirect method to jump to a new page and have it open in a new browser window without using JavaScript to register a script.
Just add attributes "OnClientClick='aspnetForm.target = '_blank';'"
to your server-side link or button. This will instruct the browser to open the link target in a new browser tab.
For example:
<code><asp:LinkButton ID="myButton" OnClick="myButton_Click" OnClientClick="aspnetForm.target='_blank';" runat="server" Text="点击我!"></asp:LinkButton></code>
On the server side, execute the Response.Redirect("MyPage.aspx")
code in the OnClick event handler and the page will open in a new window.
However, this setting may cause all links on the page to open in new windows. To resolve this issue, add the following script to the head of the popup window:
<code class="language-javascript">function fixform() { if (opener.document.getElementById("aspnetForm").target != "_blank") return; opener.document.getElementById("aspnetForm").target = ""; opener.document.getElementById("aspnetForm").action = opener.location.href; }</code>
and add <body>
in the "onload='fixform()'"
tag of the popup window. This ensures that when the popup is closed, the form's target is reset to its original value.
Through the above methods, you can effectively control page jumps and avoid the problem of all links opening in new windows, thereby achieving more sophisticated page jump management.
The above is the detailed content of How to Open a New Browser Window Using Response.Redirect in ASP.NET?. For more information, please follow other related articles on the PHP Chinese website!