• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ASP.NETJScript公共类(非常有用)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
using System.Web;

public class JScript
{
    /// <summary>
    
/// 弹出JavaScript小窗口
    
/// </summary>
    public static void Alert(string message)
    {
        string js = "<script language='JavaScript'>alert('{0}');history.go(-1);</script>";
        HttpContext.Current.Response.Write(string.Format(js, message));
    }

    /// <summary>
    
/// 弹出消息框并且转向到新的URL
    
/// </summary>
    public static void Alert(string message, string toURL)
    {
        string js = "<script language='JavaScript'>alert('{0}');window.location.replace('{1}')</script>";
        HttpContext.Current.Response.Write(string.Format(js, message, toURL));
    }

    /// <summary>
    
/// 弹出消息框并且转向到指定FRAME的新URL
    
/// </summary>
    public static void Alert(string message, string frame, string toURL)
    {
        string js = "<script language='JavaScript'>alert('{0}');{1}.location.replace('{2}')</script>";
        HttpContext.Current.Response.Write(string.Format(js, message, frame, toURL));
    }

    /// <summary>
    
/// 回到历史页面
    
/// </summary>
    public static void GoHistory(int value)
    {
        string js = "<script language='JavaScript'>history.go({0});</script>";
        HttpContext.Current.Response.Write(string.Format(js, value));
    }

    /// <summary>
    
/// 关闭当前窗口
    
/// <summary>
    public static void CloseWindow()
    {
        string js = "<script language='JavaScript'>parent.opener=null;window.close();</script>";
        HttpContext.Current.Response.Write(js);
        HttpContext.Current.Response.End();
    }

    /// <summary>
    
/// 父窗口打开指定页面
    
/// </summary>
    public static void RefreshParent(string url)
    {
        string js = "<script language='JavaScript'>window.opener.location.href='{0}';window.close();</script>";
        HttpContext.Current.Response.Write(string.Format(js, url));
    }

    /// <summary>
    
/// 刷新窗口
    
/// </summary>
    public static void RefreshWindow()
    {
        string js = "<script language='JavaScript'>opener.location.reload();</script>";
        HttpContext.Current.Response.Write(js);
    }

    /// <summary>
    
/// 打开指定大小的新窗体
    
/// </summary>
    public static void OpenWindow(string url, int width, int heigth, int top, int left)
    {
        string js = "<script language='JavaScript'>window.open('{0}', '', 'width={1}, height={2}, top={3}, left={4}, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=no, toolbar=no, directories=no');</script>";
        HttpContext.Current.Response.Write(string.Format(js, url, width, heigth, top, left));
    }

    /// <summary>
    
/// 打开新窗体
    
/// </summary>
    public static void OpenWindow(string url)
    {
        string js = "<script language='JavaScript'>window.open('{0}');</script>";
        HttpContext.Current.Response.Write(string.Format(js, url));
    }

    /// <summary>
    
/// 转向指定窗口指定Url的页面
    
/// </summary>
    public static void JsGoTo(string window, string url)
    {
        string js = "<script language='JavaScript'>{0}.location.replace('{1}');</script>";
        HttpContext.Current.Response.Write(string.Format(js, window, url));
    }

    /// <summary>
    
/// 转向指定Url的页面
    
/// </summary>
    public static void JavaScriptLocationHref(string url)
    {
        JsGoTo("window", url);
    }

    /// <summary>
    
/// 转向top指定Url的页面
    
/// </summary>
    public static void TopGoTo(string url)
    {
        JsGoTo("top", url);
    }

    /// <summary>
    
/// 转向parent指定Url的页面
    
/// </summary>
    public static void ParentGoTo(string url)
    {
        JsGoTo("parent", url);
    }

    /// <summary>
    
/// 打开指定大小位置的模式对话框
    
/// </summary>
    public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
    {
        string features = "dialogWidth:" + width.ToString() + "px"
            + ";dialogHeight:" + height.ToString() + "px"
            + ";dialogLeft:" + left.ToString() + "px"
            + ";dialogTop:" + top.ToString() + "px"
            + ";center:yes;help=no;resizable:no;status:no;scroll=yes";
        ShowModalDialogWindow(webFormUrl, features);
    }

    /// <summary>
    
/// 打开模式窗口
    
/// </summary>
    public static void ShowModalDialogWindow(string webFormUrl, string features)
    {
        string js = ShowModalDialogJavascript(webFormUrl, features);
        HttpContext.Current.Response.Write(js);
    }

    /// <summary>
    
/// 返回模式窗口脚本
    
/// </summary>
    public static string ShowModalDialogJavascript(string webFormUrl, string features)
    {
        string js = "<script language=javascript>showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
        return js;
    }

    /// <summary>
    
/// 自定义JS脚本
    
/// </summary>
    public static void Jscript(string str)
    {
        HttpContext.Current.Response.Write("<script>" + str + "</script>");
    }
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap