一些常用的Js調用類

來源:互聯網
上載者:User
js

using System;
using System.Web;
using System.Web.UI;

using System;
using System.Web;
using System.Web.UI;

namespace 4ec{
    /// <summary>
    /// 一些常用的Js調用
    /// </summary>
    public class Jscript
    {       
              
        /// <summary>
        /// 彈出JavaScript小視窗
        /// </summary>
        /// <param name="js">視窗資訊</param>
        public static void Alert(string message)
        {
            #region
            string js = @"<Script language='JavaScript'>
                    alert('" + message + "');</Script>";
            HttpContext.Current.Response.Write(js);
            #endregion
        }

        /// <summary>
        /// 彈出訊息框並且轉向到新的URL
        /// </summary>
        /// <param name="message">訊息內容</param>
        /// <param name="toURL">串連地址</param>
        public static void AlertAndRedirect(string message, string toURL)
        {
            #region
            string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
            HttpContext.Current.Response.Write(string.Format(js, message, toURL));
            #endregion
        }
       
        /// <summary>
        /// 回到曆史頁面
        /// </summary>
        /// <param name="value">-1/1</param>
        public static void GoHistory(int value)
        {
            #region
            string js = @"<Script language='JavaScript'>
                    history.go({0}); 
                  </Script>";
            HttpContext.Current.Response.Write(string.Format(js, value));
            #endregion
        }

        /// <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)
        {
            #region
            string js = @"<script>try{top.location=""" +url+@"""}catch(e){location="""+url+@"""}</script>";
            HttpContext.Current.Response.Write(js);
            #endregion
        }

      
        /// <summary>
        /// 重新整理開啟視窗
        /// </summary>
        public static void RefreshOpener()
        {
            #region
            string js = @"<Script language='JavaScript'>
                    opener.location.reload();
                  </Script>";
            HttpContext.Current.Response.Write(js);
            #endregion
        }


        /// <summary>
        /// 開啟指定大小的新表單
        /// </summary>
        /// <param name="url">地址</param>
        /// <param name="width">寬</param>
        /// <param name="heigth">高</param>
        /// <param name="top">頭位置</param>
        /// <param name="left">左位置</param>
        public static void OpenWebFormSize(string url, int width,int heigth,int top,int left)
        {
            #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);
            #endregion
        }
      
       
        /// <summary>
        /// 轉向Url制定的頁面
        /// </summary>
        /// <param name="url">串連地址</param>
        public static void JavaScriptLocationHref(string url)
        {
            #region
            string js = @"<Script language='JavaScript'>
                    window.location.replace('{0}');
                  </Script>";
            js = string.Format(js, url);
            HttpContext.Current.Response.Write(js);
            #endregion
        }

        /// <summary>
        /// 開啟指定大小位置的強制回應對話方塊
        /// </summary>
        /// <param name="webFormUrl">串連地址</param>
        /// <param name="width">寬</param>
        /// <param name="height">高</param>
        /// <param name="top">距離上位置</param>
        /// <param name="left">距離左位置</param>
        public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
        {
            #region
            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);
            #endregion
        }

        public static void ShowModalDialogWindow(string webFormUrl, string features)
        {
            string js = ShowModalDialogJavascript(webFormUrl, features);
            HttpContext.Current.Response.Write(js);
        }

        public static string ShowModalDialogJavascript(string webFormUrl, string features)
        {
            #region
            string js = @"<script language=javascript>      
       showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
            return js;
            #endregion
        }
      

    }
}


 



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。