[C#] C#封装的JS(JavaScript)操作类 →→→→→进入此内容的聊天室

来自 , 2019-05-17, 写在 C#, 查看 117 次.
URL http://www.code666.cn/view/5616060f
  1. using System.Web;
  2.  
  3. namespace DotNet.Utilities
  4. {
  5.     /// <summary>
  6.     /// 客户端脚本输出
  7.     /// </summary>
  8.     public class JsHelper
  9.     {
  10.         /// <summary>
  11.         /// 弹出信息,并跳转指定页面。
  12.         /// </summary>
  13.         public static void AlertAndRedirect(string message, string toURL)
  14.         {
  15.             string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
  16.             HttpContext.Current.Response.Write(string.Format(js, message, toURL));
  17.             HttpContext.Current.Response.End();
  18.         }
  19.  
  20.         /// <summary>
  21.         /// 弹出信息,并返回历史页面
  22.         /// </summary>
  23.         public static void AlertAndGoHistory(string message, int value)
  24.         {
  25.             string js = @"<Script language='JavaScript'>alert('{0}');history.go({1});</Script>";
  26.             HttpContext.Current.Response.Write(string.Format(js, message, value));
  27.             HttpContext.Current.Response.End();
  28.         }
  29.  
  30.         /// <summary>
  31.         /// 直接跳转到指定的页面
  32.         /// </summary>
  33.         public static void Redirect(string toUrl)
  34.         {
  35.             string js = @"<script language=javascript>window.location.replace('{0}')</script>";
  36.             HttpContext.Current.Response.Write(string.Format(js, toUrl));
  37.         }
  38.  
  39.         /// <summary>
  40.         /// 弹出信息 并指定到父窗口
  41.         /// </summary>
  42.         public static void AlertAndParentUrl(string message, string toURL)
  43.         {
  44.             string js = "<script language=javascript>alert('{0}');window.top.location.replace('{1}')</script>";
  45.             HttpContext.Current.Response.Write(string.Format(js, message, toURL));
  46.         }
  47.  
  48.         /// <summary>
  49.         /// 返回到父窗口
  50.         /// </summary>
  51.         public static void ParentRedirect(string ToUrl)
  52.         {
  53.             string js = "<script language=javascript>window.top.location.replace('{0}')</script>";
  54.             HttpContext.Current.Response.Write(string.Format(js, ToUrl));
  55.         }
  56.  
  57.         /// <summary>
  58.         /// 返回历史页面
  59.         /// </summary>
  60.         public static void BackHistory(int value)
  61.         {
  62.             string js = @"<Script language='JavaScript'>history.go({0});</Script>";
  63.             HttpContext.Current.Response.Write(string.Format(js, value));
  64.             HttpContext.Current.Response.End();
  65.         }
  66.  
  67.         /// <summary>
  68.         /// 弹出信息
  69.         /// </summary>
  70.         public static void Alert(string message)
  71.         {
  72.             string js = "<script language=javascript>alert('{0}');</script>";
  73.             HttpContext.Current.Response.Write(string.Format(js, message));
  74.         }
  75.  
  76.         /// <summary>
  77.         /// 注册脚本块
  78.         /// </summary>
  79.         public static void RegisterScriptBlock(System.Web.UI.Page page, string _ScriptString)
  80.         {
  81.             page.ClientScript.RegisterStartupScript(page.GetType(), "scriptblock", "<script type='text/javascript'>" + _ScriptString + "</script>");
  82.         }
  83.     }
  84. }
  85. //csharp/8617

回复 "C#封装的JS(JavaScript)操作类"

这儿你可以回复上面这条便签

captcha