js类库

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// JS 常用方法
/// </summary>
public class JScript
{
    #region  打开WEB窗口(是否全屏幕)
    /// <summary> 
    /// </summary>
    /// <param name="url">WEB窗口</param>
    /// <param name="isFullScreen">是否全屏幕</param>
    public static void OpenWebForm(string url, bool isFullScreen)
    {
        string js = @"<Script type='text/javascript'>";
        if (isFullScreen)
        {
            js += "var iWidth = 0;";
            js += "var iHeight = 0;";
            js += "iWidth=window.screen.availWidth-10;";
            js += "iHeight=window.screen.availHeight-30;";
            js += "var szFeatures ='width=' + iWidth + ',height=' + iHeight + ',top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,directories=no';";
            js += "window.open('" + url + @"','',szFeatures);";
        }
        else
        {
            js += "window.open('" + url + @"','','height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,directories=no');";
        }
        js += "</Script>";
        HttpContext.Current.Response.Write(js);
    }
    #endregion
   
    /// <summary>
    /// 弹出信息(message)
    /// </summary>
    /// <param name="message"></param>
    public static void Alert(object message)
    {
        string js = @"<Script language='JavaScript'>
                    alert('{0}'); 
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString()));
    }
    /// <summary>
    /// 弹出信息((message+url))
    /// </summary>
    /// <param name="message"></param>
    /// <param name="url"></param>
    public static void Alert(object message, string url)
    {
        string js = @"<Script language='JavaScript'>
                    alert('{0}');window.open('{1}','_parent') 
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString(), url));
    }
    /// <summary>
    /// 弹出信息((message+url+target))
    /// </summary>
    /// <param name="message"></param>
    /// <param name="url"></param>
    /// <param name="target"></param>
    public static void Alert(object message, string url, string target)
    {
        string js = @"<Script language='JavaScript'>
                    alert('{0}');window.open('{1}','{2}') 
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString(), url, target));
    }
    /// <summary>
    /// 跳转并刷新

    /// </summary>
    /// <param name="message"></param>
    /// <param name="url"></param>
    public static void AlertRefresh(object message, string url)
    {
        string js = @"<Script language='JavaScript'>
                    alert('{0}'); window.location.href='{1}'
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString(), url));
    }
    /// <summary>
    /// 指定框架刷新(url+target)
    /// </summary>
    /// <param name="url"></param>
    /// <param name="target"></param>
    public static void AlertRefresh(string url, string target)
    {
        string js = @"<Script language='JavaScript'>
                    window.open('{0}','{1}')   
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, url, target));
    }
    /// <summary>
    /// 弹出页面并刷新父页面并关闭子页面
    /// </summary>
    /// <param name="message"></param>
    public static void AlertRefreshParentClose(object message)
    {
        string js = @"<script language='javascript'>alert('{0}'); window.dialogArguments.location.reload(true);window.close();window.parent.opener=null;window.parent.close(); </script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString()));  
    }
    /// <summary>
    /// 刷新
    /// </summary>
    /// <param name="url"></param>
    public static void Refresh(string url)
    {
        string js = @"<Script language='JavaScript'>
                     window.location.href='{0}'
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, url));
    }
    /// <summary>
    /// 跳转
    /// </summary>
    /// <param name="message"></param>
    /// <param name="url"></param>
    public static void resp(string url, string target)
    {
        string js = @"<Script language='JavaScript'>
                    window.open('{0}','{1}') 
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, url, target));
    }
    /// <summary>
    /// 指定框架刷新(message+url+target)
    /// </summary>
    /// <param name="message"></param>
    /// <param name="url"></param>
    /// <param name="target"></param>
    public static void AlertRefresh(object message, string url, string target)
    {
        string js = @"<Script language='JavaScript'>
                    alert('{0}');window.location.href=('{1}','{2}') 
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString(), url, target));
    }
    /// <summary>
    /// 不知道啊
    /// </summary>
    /// <param name="url"></param>
    /// <param name="target"></param>
    public static void AlertRefreshFrames(string url, string target)
    {
        string js = @"<Script language='JavaScript'>
                    window.frames['{1}'].src='{0}'
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, url, target));
    }
    /// <summary>
    /// 确认
    /// </summary>
    /// <param name="message"></param>
    public static void Confirm(object message)
    {
        string js = @"<Script language='JavaScript'>
                    confirm('{0}'); 
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString()));
    }
    /// <summary>
    /// 确认并跳转页面

    /// </summary>
    /// <param name="message"></param>
    /// <param name="url"></param>
    public static void ConfirmAlert(object message, string url)
    {
        string js = @"<Script language='JavaScript'>
                    confirm('{0}');window.open('{1}','_parent')
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString(), url));
    }
    public static void ConfirmAlert(object message, string url, string target)
    {
        string js = @"<Script language='JavaScript'>
                    confirm('{0}');window.open('{1}','{2}')
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString(), url, target));
    }
    /// <summary>
    /// 输入指定js
    /// </summary>
    /// <param name="js"></param>
    public static void ResponseJs(string js)
    {
        HttpContext.Current.Response.Write(js);
    }
    /// <summary>
    /// 关闭父窗体

    /// </summary>
    public static void CloseParentWindow()
    {
        string js = @"<Script type='text/javascript'>
                    window.parent.opener=null;window.parent.close(); 
                  </Script>";
        HttpContext.Current.Response.Write(js);
    }
}

你可能感兴趣的:(js)