JavaScript操作类

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>
/// 调用JavaScript脚本
/// </summary>
public class JScript : System.Web.UI.Page
{
 public JScript()
 {
  //
  // TODO: 在此处添加构造函数逻辑
  //
 }
    public static void AlertAndRedirect(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>
    /// 弹出JavaScript小窗口
    /// </summary>
    /// <param name="js">窗口信息</param>
    public static void Alert(string message)
    {
        message = StringUtil.DeleteUnVisibleChar(message);
        string js = @"<Script language='JavaScript'>
                    alert('" + message + "');</Script>";
        HttpContext.Current.Response.Write(js);
    }
    //public static  void Alert(string strMessage)
    //{
    //    //Page.RegisterStartupScript("","<script>alert('"+strMessage+"');</script>");
    //    string js = @"<script language='JavaScript'>alert('"+strMessage+"');</script>";
    //    HttpContext.Current.Response.Write(js);

    //}
    public static void Alert(object message)
    {
        string js = @"<Script language='JavaScript'>
                    alert('{0}'); 
                  </Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString()));
    }

    public static void RtnRltMsgbox(object message, string strWinCtrl)
    {
        string js = @"<Script language='JavaScript'>
      strWinCtrl = true;
                     strWinCtrl = if(!confirm('" + message + "'))return false;</Script>";
        HttpContext.Current.Response.Write(string.Format(js, message.ToString()));
    }
    /// <summary>
    /// 拥有'确定'/'取消'按钮的对话框
    /// </summary>
    /// <param name="strText">对话框的文本信息</param>
    /// <param name="strURL">重新定向的地址</param>
    public static void MessageBoxYesNo(string strText, string strURL)
    {
        HttpContext.Current.Response.Write("<script language='javascript'>var ans;");
        HttpContext.Current.Response.Write("ans=window.confirm('" + strText + "');");
        HttpContext.Current.Response.Write("if (ans==true){window.location='" + strURL + "';}</script>");
        HttpContext.Current.Response.Write("</script>");
       
    }
    /// <summary>
    /// 回到历史页面
    /// </summary>
    /// <param name="value">-1/1</param>
    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'>
                    window.close(); 
                  </Script>";
        HttpContext.Current.Response.Write(js);
        HttpContext.Current.Response.End();
    }

    /// <summary>
    /// 刷新父窗口
    /// </summary>
    public static void RefreshParent()
    {
        string js = @"<Script language='JavaScript'>
                    parent.location.reload();
                  </Script>";
        HttpContext.Current.Response.Write(js);
    }
    /// <summary>
    /// 打开窗口
    /// </summary>
    /// <param name="url"></param>
    public static void OpenWebForm(string url)
    {

        /*…………………………………………………………………………………………*/
        /*开始*/
        string js = @"<Script language='JavaScript'>
   //window.open('" + url + @"');
   window.open('" + url + @"','','height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');
   </Script>";
        /*结束*/
        /*…………………………………………………………………………………………*/


        HttpContext.Current.Response.Write(js);
    }
    public static void OpenWebForm(string url, string formName)
    {
        /*…………………………………………………………………………………………*/
        /*修改人员:  sxs      */
        /*修改时间: 2003-4-9 */
        /*修改目的: 新开页面去掉ie的菜单。。。      */
        /*注释内容:        */
        /*开始*/
        string js = @"<Script language='JavaScript'>
   //window.open('" + url + @"','" + formName + @"');
   window.open('" + url + @"','" + formName + @"','height=0,width=0,top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');
   </Script>";
        /*结束*/
        /*…………………………………………………………………………………………*/

        HttpContext.Current.Response.Write(js);
    }
    /// </summary>
    /// <param name="url">WEB窗口</param>
    /// <param name="isFullScreen">是否全屏幕</param>
    public static void OpenWebForm(string url, bool isFullScreen)
    {
        string js = @"<Script language='JavaScript'>";
        if (isFullScreen)
        {
            js += "var iWidth = 0;";
            js += "var iHeight = 0;";
            js += "iWidth=window.screen.availWidth-10;";
            js += "iHeight=window.screen.availHeight-50;";
            js += "var szFeatures ='width=' + iWidth + ',height=' + iHeight + ',top=0,left=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,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=yes,titlebar=no,toolbar=no,directories=no');";
        }
        js += "</Script>";
        HttpContext.Current.Response.Write(js);
    }
    /// <summary>
    /// 转向Url制定的页面
    /// </summary>
    /// <param name="url"></param>
    public static void JavaScriptLocationHref(string url)
    {
        string js = @"<Script language='JavaScript'>
                    window.location.replace('{0}');
                  </Script>";
        js = string.Format(js, url);
        HttpContext.Current.Response.Write(js);
    }
    /// </summary>
    /// <param name="parentWindowUrl">父窗口</param>  
    public static void GotoParentWindow(string parentWindowUrl)
    {
        string js = @"<Script language='JavaScript'>
                    this.parent.location.replace('" + parentWindowUrl + "');</Script>";
        HttpContext.Current.Response.Write(js);
    }
    /// <summary>
    /// 函数名:ShowModalDialogJavascript 
    /// 功能描述:返回打开模式窗口的脚本 
    /// 处理流程:
    /// 算法描述:
    /// 作 者: 孙洪彪
    /// 日 期: 2003-04-30 15:00
    /// 修 改:
    /// 日 期:
    /// 版 本:
    /// </summary>
    /// <param name="webFormUrl"></param>
    /// <returns></returns>
    public static string ShowModalDialogJavascript(string webFormUrl)
    {
        string js = @"<script language=javascript>
       var iWidth = 0 ;
       var iHeight = 0 ;
       iWidth=window.screen.availWidth-10;
       iHeight=window.screen.availHeight-50;
       var szFeatures = 'dialogWidth:'+iWidth+';dialogHeight:'+iHeight+';dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes';
       showModalDialog('" + webFormUrl + "','',szFeatures);</script>";
        return js;
    }

    public static string ShowModalDialogJavascript(string webFormUrl, string features)
    {
        string js = @"<script language=javascript>       
       showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
        return js;
    }
    /// <summary>
    /// 函数名:ShowModalDialogWindow 
    /// 功能描述:打开模式窗口 
    /// 处理流程:
    /// 算法描述:
    /// 作 者: 孙洪彪
    /// 日 期: 2003-04-30 15:00
    /// 修 改:
    /// 日 期:
    /// 版 本:
    /// </summary>
    /// <param name="webFormUrl"></param>
    /// <returns></returns>
    public static void ShowModalDialogWindow(string webFormUrl)
    {
        string js = ShowModalDialogJavascript(webFormUrl);
        HttpContext.Current.Response.Write(js);
    }

    public static void ShowModalDialogWindow(string webFormUrl, string features)
    {
        string js = ShowModalDialogJavascript(webFormUrl, features);
        HttpContext.Current.Response.Write(js);
    }
    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=no";
        ShowModalDialogWindow(webFormUrl, features);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值