How to Open a Response.Redirect in a New Browser Window?
Jan 08, 2025 pm 02:57 PMRedirecting to a New Browser Window
For a smoother user experience when using Response.Redirect
, opening the redirected page in a new browser tab or window is often preferred. This avoids disrupting the current page. A straightforward method avoids the complexity of using JavaScript's register script
function.
To achieve this, simply add a specific attribute to your server-side link or button:
OnClientClick="aspnetForm.target='_blank';"
Here's an example using a button:
<asp:Button ID="myButton" runat="server" Text="Click Me!" OnClick="myButton_Click" OnClientClick="aspnetForm.target='_blank';" />
In the server-side OnClick
event (myButton_Click
), execute your Response.Redirect
. The redirected page will now open in a new window.
To prevent unintended behavior where all links open in new windows, include this JavaScript function in the header of your popup window:
function fixform() { if (opener.document.getElementById("aspnetForm").target != "_blank") return; opener.document.getElementById("aspnetForm").target = ""; opener.document.getElementById("aspnetForm").action = opener.location.href; }
And add this to the body tag of your popup window:
onload="fixform();"
This ensures that only the intended links open in new windows.
The above is the detailed content of How to Open a Response.Redirect in a New Browser Window?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the types of values returned by c language functions? What determines the return value?

C language function format letter case conversion steps

What are the definitions and calling rules of c language functions and what are the

Where is the return value of the c language function stored in memory?

How do I use algorithms from the STL (sort, find, transform, etc.) efficiently?

How does the C Standard Template Library (STL) work?
