ASP.NET中常用输出JS脚本的类实例(4)

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

/// <summary>
    /// 刷新父窗口
    /// </summary>
    public static void RefreshParent(string url, Page page)
    {
        #region
        string js = @"<Script language='JavaScript'>
                    window.opener.location.href='" + url + "';window.close();</Script>";
        //HttpContext.Current.Response.Write(js);
        if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "RefreshParent"))
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "RefreshParent", js);
        }
        #endregion
    }


    /// <summary>
    /// 刷新打开窗口
    /// </summary>
    public static void RefreshOpener(Page page)
    {
        #region
        string js = @"<Script language='JavaScript'>
                    opener.location.reload();
                  </Script>";
        //HttpContext.Current.Response.Write(js);
        if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "RefreshOpener"))
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "RefreshOpener", js);
        }
        #endregion
    }


    /// <summary>
    /// 打开指定大小的新窗体
    /// </summary>
    /// <param>地址</param>
    /// <param>宽</param>
    /// <param>高</param>
    /// <param>头位置</param>
    /// <param>左位置</param>
    public static void OpenWebFormSize(string url, int width, int heigth, int top, int left, Page page)
    {
        #region
        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>";
        //HttpContext.Current.Response.Write(js);
        if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "OpenWebFormSize"))
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "OpenWebFormSize", js);
        }
        #endregion
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzdgs.html