简体   繁体   English

如何打开新浏览器 Window

[英]How Open New Browser Window

I am using Asp.net c# develop web application我正在使用 Asp.net c# 开发 web 应用程序

How can I open up a response.redirect in a new browser window?如何在新浏览器 window 中打开 response.redirect?

eg Response.Redirect( http://www.asp.net );例如响应。重定向( http://www.asp.net );

Thanks谢谢

This is a quite common question, and the answer is that you can't.这是一个很常见的问题,答案是你不能。

The reason is that it's decided already when the browser sends the request to the server where the page will be loaded, so when the code starts running at the server it's too late to change where the page will be loaded.原因是浏览器何时将请求发送到将加载页面的服务器已经确定,因此当代码开始在服务器上运行时,更改页面的加载位置为时已晚。

You can add javascript to the page that will open a new window, but you still have to send a page back to the browser as a response to the request (ie you can't leave the current page in the browser, as the browser has already requested a page to replace it).您可以将 javascript 添加到将打开新 window 的页面,但您仍然必须将页面发送回浏览器作为对请求的响应(即您不能将当前页面留在浏览器中,因为浏览器已经已经请求了一个页面来替换它)。

ClientScript.RegisterStartupScript(this.GetType(), "aspnet", "window.open('http://www.asp.net','_blank');", true);

Unfortunately you cannot do this from the server, you will have to use client side code to create a new browser window.不幸的是,您无法从服务器执行此操作,您将不得不使用客户端代码来创建新的浏览器 window。 You could do this with the Javascript function window.open .您可以使用 Javascript function window.open来做到这一点。

One way of doing this would be to embed the URL you wish to send the user to in a hidden input and then when the page renders have a Javascript function that would check that input for a value and if it found one it would do the window.open call. One way of doing this would be to embed the URL you wish to send the user to in a hidden input and then when the page renders have a Javascript function that would check that input for a value and if it found one it would do the window.open通话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在焦点浏览器中打开一个新窗口 - How to open a new window in browser with focus 使用NavigateUrl,如何在浏览器中打开一个新窗口而不是一个选项卡? - Using NavigateUrl, how to open a new window instead of a tab in the browser? 如何在新的浏览器窗口中打开下载的文件C# - How to open the downloaded file in new browser window c# 如何在按钮点击事件上打开新的浏览器窗口? - How to open new browser window on button click event? 如何在 C#、WinUI 3 中打开新的浏览器 window? - How to open new browser window in C#, WinUI 3? 如何在 C#.net 中打开 Edge 浏览器的新 window 而不是新选项卡 - How to Open New window of Edge browser instead of new tab in C#.net 如何在新的浏览器窗口中打开在数据库(SQL Server)中存储为blob的文件? - How do you open a file that is stored as blob in the db (SQL server) in new browser window? 如何从asp.net 处理程序文件打开新的浏览器窗口? - how to open new browser window from asp.net handler file? 单击富文本框中的链接后如何打开新的浏览器窗口(C#) - How to open a new browser window after clicking on a link in rich text box(C#) 如何在lightswitch应用程序中打开浏览器窗口? - How to open browser window in lightswitch application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM