Redirecting 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:
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!