Classes frequently called by JavaScript

From , 3 Years ago, written in C#, viewed 84 times.
URL https://pastebin.vip/view/74934548
  1. /// <summary>
  2.    /// 一些常用的Js调用
  3.    /// </summary>
  4.    public class JScript
  5.    {
  6.        /// <summary>
  7.        /// 弹出JavaScript小窗口
  8.        /// </summary>
  9.        /// <param name="js">窗口信息</param>
  10.        public static void Extjs(string message)
  11.        {
  12.            #region
  13.            string js = @"<Script language='JavaScript'>" + message + "</Script>";
  14.            HttpContext.Current.Response.Write(js);
  15.            #endregion
  16.        }
  17.  
  18.        /// <summary>
  19.        /// 弹出JavaScript小窗口
  20.        /// </summary>
  21.        /// <param name="js">窗口信息</param>
  22.        public static void Alert(string message)
  23.        {
  24.            #region
  25.            string js = @"<Script language='JavaScript'>
  26.                   alert('" + message + "');</Script>";
  27.            HttpContext.Current.Response.Write(js);
  28.            #endregion
  29.        }
  30.  
  31.        /// <summary>
  32.        /// 弹出消息框并且转向到新的URL
  33.        /// </summary>
  34.        /// <param name="message">消息内容</param>
  35.        /// <param name="toURL">连接地址</param>
  36.        public static void AlertAndRedirect(string message, string toURL)
  37.        {
  38.            #region
  39.            string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
  40.            HttpContext.Current.Response.Write(string.Format(js, message, toURL));
  41.            #endregion
  42.        }
  43.  
  44.        /// <summary>
  45.        /// 回到历史页面
  46.        /// </summary>
  47.        /// <param name="value">-1/1</param>
  48.        public static void GoHistory(int value)
  49.        {
  50.            #region
  51.            string js = @"<Script language='JavaScript'>
  52.                   history.go({0});
  53.                 </Script>";
  54.            HttpContext.Current.Response.Write(string.Format(js, value));
  55.            #endregion
  56.        }
  57.  
  58.        /// <summary>
  59.        /// 关闭当前窗口
  60.        /// </summary>
  61.        public static void CloseWindow()
  62.        {
  63.            #region
  64.            string js = @"<Script language='JavaScript'>
  65.                   parent.opener=null;window.close();
  66.                 </Script>";
  67.            HttpContext.Current.Response.Write(js);
  68.            HttpContext.Current.Response.End();
  69.            #endregion
  70.        }
  71.  
  72.        /// <summary>
  73.        /// 刷新父窗口
  74.        /// </summary>
  75.        public static void RefreshParent(string url)
  76.        {
  77.            #region
  78.            string js = @"<Script language='JavaScript'>
  79.                   window.opener.location.href='" + url + "';window.close();</Script>";
  80.            HttpContext.Current.Response.Write(js);
  81.            #endregion
  82.        }
  83.  
  84.  
  85.        /// <summary>
  86.        /// 刷新打开窗口
  87.        /// </summary>
  88.        public static void RefreshOpener()
  89.        {
  90.            #region
  91.            string js = @"<Script language='JavaScript'>
  92.                   opener.location.reload();
  93.                 </Script>";
  94.            HttpContext.Current.Response.Write(js);
  95.            #endregion
  96.        }
  97.  
  98.  
  99.        /// <summary>
  100.        /// 打开指定大小的新窗体
  101.        /// </summary>
  102.        /// <param name="url">地址</param>
  103.        /// <param name="width">宽</param>
  104.        /// <param name="heigth">高</param>
  105.        /// <param name="top">头位置</param>
  106.        /// <param name="left">左位置</param>
  107.        public static void OpenWebFormSize(string url, int width, int heigth, int top, int left)
  108.        {
  109.            #region
  110.            string js = @"<Script language='JavaScript'>window.open('" + url + @"','','height=" + heigth + ",width=" + width + ",top=" + top + ",left=" + left + ",location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');</Script>";
  111.  
  112.            HttpContext.Current.Response.Write(js);
  113.            #endregion
  114.        }
  115.  
  116.  
  117.        /// <summary>
  118.        /// 转向Url制定的页面
  119.        /// </summary>
  120.        /// <param name="url">连接地址</param>
  121.        public static void JavaScriptLocationHref(string url)
  122.        {
  123.            #region
  124.            string js = @"<Script language='JavaScript'>
  125.                   window.location.replace('{0}');
  126.                 </Script>";
  127.            js = string.Format(js, url);
  128.            HttpContext.Current.Response.Write(js);
  129.            #endregion
  130.        }
  131.  
  132.        /// <summary>
  133.        /// 打开指定大小位置的模式对话框
  134.        /// </summary>
  135.        /// <param name="webFormUrl">连接地址</param>
  136.        /// <param name="width">宽</param>
  137.        /// <param name="height">高</param>
  138.        /// <param name="top">距离上位置</param>
  139.        /// <param name="left">距离左位置</param>
  140.        public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
  141.        {
  142.            #region
  143.            string features = "dialogWidth:" + width.ToString() + "px"
  144.                + ";dialogHeight:" + height.ToString() + "px"
  145.                + ";dialogLeft:" + left.ToString() + "px"
  146.                + ";dialogTop:" + top.ToString() + "px"
  147.                + ";center:yes;help=no;resizable:no;status:no;scroll=yes";
  148.            ShowModalDialogWindow(webFormUrl, features);
  149.            #endregion
  150.        }
  151.  
  152.        public static void ShowModalDialogWindow(string webFormUrl, string features)
  153.        {
  154.            string js = ShowModalDialogJavascript(webFormUrl, features);
  155.            HttpContext.Current.Response.Write(js);
  156.        }
  157.  
  158.        public static string ShowModalDialogJavascript(string webFormUrl, string features)
  159.        {
  160.            #region
  161.            string js = @"<script language=javascript>                          
  162.                           showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
  163.            return js;
  164.            #endregion
  165.        }
  166.  
  167.        /// <summary>
  168.        /// 返回错误信息格式
  169.        /// </summary>
  170.        /// <param name="s"></param>
  171.        /// <returns></returns>
  172.        public static string errinfo(string[] s)
  173.        {
  174.            string str = "<ul>";
  175.            for (int i = 0; i < s.Length; i++)
  176.            {
  177.                str=str+"<li>"+s[i]+"</li>";
  178.            }
  179.            str = str+"</ul>";
  180.            return str;
  181.        }
  182.  
  183.        /// <summary>
  184.        /// 返回错误信息格式
  185.        /// </summary>
  186.        /// <param name="s"></param>
  187.        /// <returns></returns>
  188.        public static string errinfo(string s)
  189.        {
  190.            return "<ul><li>" + s + "</li></ul>";    
  191.        }
  192.  
  193.    }

Reply to "Classes frequently called by JavaScript"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website