C#输出JS代码封装类-Alart

 /// <summary>
    /// Alart 的摘要说明
    /// </summary>
    public class Alart
    {
        public enum  AlartState
        {
            /// <summary>
            /// 在根窗口中打开该连接
            /// </summary>
            OpenInTopWindow,
            /// <summary>
            /// 在父窗口中打开该连接
            /// </summary>
            OpenInParentWindow,
            /// <summary>
            /// 在当前窗口中打开该连接
            /// </summary>
            OpenInThisWindow,
            /// <summary>
            /// 返回到上一个页面
            /// </summary>
            Back,
            /// <summary>
            /// 关闭窗口
            /// </summary>
            CloseWindow,
            /// <summary>
            /// 不做任何操作
            /// </summary>
            Nothing
        }

        /// <summary>
        /// 输出JS提示信息对话框
        /// </summary>
        /// <param name="context">页面Context</param>HttpContext.Current
        /// <param name="msg">消息内容</param>
        /// <param name="alartState">输出模式*枚举</param>
        /// <param name="toUrl">提示后要转到的URL</param>
        public static void ShowAlart(HttpContext context, string msg, AlartState alartState,string toUrl)
        {
            StringBuilder mySB = new StringBuilder();
            mySB.AppendFormat("<script language='javascript'>alert('{0}');", msg);
            switch (alartState)
            {
                case AlartState.Back:
                    mySB.Append("history.go(-1)");
                    break;
                case AlartState.CloseWindow:
                    mySB.Append("top.window.close()");
                    break;
                case AlartState.OpenInParentWindow:
                    mySB.AppendFormat("parent.location='{0}'",toUrl);
                    break;
                case AlartState.OpenInThisWindow:
                    mySB.AppendFormat("window.locaiton='{0}'", toUrl);
                    break;
                case AlartState.OpenInTopWindow:
                    mySB.AppendFormat("top.location='{0}'", toUrl);
                    break;
                case AlartState.Nothing:
                    break;
            }
            mySB.Append("</script>");
            context.Response.Write(mySB);
            context.Response.End();
        }

        /// <summary>
        /// 输出JS
        /// </summary>
        /// <param name="context">页面Context</param>HttpContext.Current
        /// <param name="jsStr">脚本</param>
        public static void UseJs(HttpContext context,string jsStr)
        {
            StringBuilder mySB = new StringBuilder();
            mySB.AppendFormat("<script language='javascript'>{0}", jsStr);
            mySB.Append("</script>");
            context.Response.End();
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值