您现在的位置是:首页 >

js页面跳转不打开新窗口 使用Response.Redirect打开新窗口的方法

火烧 2022-09-30 06:14:02 1167
使用Re o e.Redirect打开新窗口的方法   方法一   rotected void Page_Load o ject e der Eve tArg e   {  form Target =

使用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

  {

js页面跳转不打开新窗口 使用Response.Redirect打开新窗口的方法

  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  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码