js页面跳转不打开新窗口 使用Response.Redirect打开新窗口的方法
使用Response.Redirect打开新窗口的方法
方法一
protected void Page_Load(object sender EventArgs e)
{
form Target = _blank ;
}
protected void Button _Click(object sender EventArgs e)
{
Response Redirect( );
}
办法二 采用客户端脚本的方法设置 target 属性 代码如下
复制 保存
protected void Page_Load(object sender EventArgs e)
{
Button Attributes Add( onclick this form target= _newName );
}
protected void Button _Click(object sender EventArgs e)
{
Response Redirect( );
}
方法三
protected void Page_Load(object sender EventArgs e)
{
string WindowName = win + System DateTime Now Ticks ToString();
Page RegisterOnSubmitStatement( js window open( + WindowName + width= height= ) );
form Target = WindowName;
}
protected void Button _Click(object sender EventArgs e)
{
Response Redirect( );
}
方法
public static class ResponseHelper
{

public static void Redirect(string url string target string windowFeatures)
{
HttpContext context = HttpContext Current;
if ((String IsNullOrEmpty(target) || target Equals( _self StringComparison OrdinalIgnoreCase)) && String IsNullOrEmpty(windowFeatures))
{
context Response Redirect(url);
}
else
{
Page page = (Page)context Handler;
if (page == null)
{
throw new InvalidOperationException( Cannot redirect to new window outside Page context );
} url = page ResolveClientUrl(url); string script; if (!String IsNullOrEmpty(windowFeatures))
{ script = @ <script>window open( { } { } { } );</script> ; }
else
{
script = @ <script>window open( { } { } );</script> ;
}
script = String Format(script url target windowFeatures);
//ScriptManager RegisterStartupScript(page typeof(Page) Redirect script true);
page RegisterStartupScript( ddd script);
}
}
}
调用
lishixinzhi/Article/program/net/201311/11924