在asp.net中的新窗口中打开URL [英] Open the url in new window in asp.net
问题描述
我正在使用一个网格视图,在该视图中,在一列中以超链接或按钮的形式查看文件路径,并且单击链接时在新窗口或新选项卡中打开url,我想使用javascript(window.open)
这是我的代码
Hi,
I am using an grid view in which file paths are viewed in one column as an hyperlink or button and when clicked the link open the url in new window or in new tab, I thought to do this by using javascript (window.open)
and here is my code
string url="~/Files/file1.doc";
StringBuilder sb = new StringBuilder();
sb.Append("<script type='text/javascript'>"); sb.Append("window.open('"+url+"');");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "Testing",sb.ToString());
但是我的网址仍然在同一窗口中打开,
谁能告诉我我是否做错了,什么是最好的方法来解决这个问题?
在此先感谢...
But still my url opens in the same window,
Can anyone tell me whether i went wrong, what is the best way to work this...
Thanks in advance...
推荐答案
确定!
只需命名或在新窗口的名称中使用''_ blank'',它将以新名称打开,而不是在同一页面上.
例如:"myWindowName"是需要指定的名称.
Sure!
Just give a name OR use ''_blank'' in the name to the new windows and it will open up as a new one instead of on the same page.
For ex: ''myWindowName'' is the name that needs to be given.
var reportWindow = window.open('CostByProject.aspx', 'myWindowName','height=650,width=900,resizable=1,status=yes,scrollbars=1,toolbar=no,menubar=no,location=no');
在此处阅读详细信息: MSDN:Window.Open() [ ^ ]
附注:"_ blank"也可以在名称中使用,但它始终会触发一个新窗口.
Read the details here: MSDN: Window.Open()[^]
P.S.: "_blank" can also be used in the name place but it will always trigger a new window.
这篇关于在asp.net中的新窗口中打开URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!