• Asp.net封装js的类


      1 using System;
      2 using System.Collections.Generic;
      3 using System.Text;
      4 using System.Web;
      5 using System.Web.UI;
      6 
      7 /// </summary>
      8 public class JScript
      9 {
     10     #region 旧版本
     11     /// <summary>
     12     /// 弹出JavaScript小窗口
     13     /// </summary>
     14     /// <param name="js">窗口信息</param>
     15     public static void Alert(string message)
     16     {
     17         #region
     18         string js = @"<Script language='JavaScript'>
     19                     alert('" + message + "');</Script>";
     20         HttpContext.Current.Response.Write(js);
     21         #endregion
     22     }
     23 
     24     /// <summary>
     25     /// 弹出消息框并且转向到新的URL
     26     /// </summary>
     27     /// <param name="message">消息内容</param>
     28     /// <param name="toURL">连接地址</param>
     29     public static void AlertAndRedirect(string message, string toURL)
     30     {
     31         #region
     32         string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
     33         HttpContext.Current.Response.Write(string.Format(js, message, toURL));
     34         #endregion
     35     }
     36 
     37     /// <summary>
     38     /// 回到历史页面
     39     /// </summary>
     40     /// <param name="value">-1/1</param>
     41     public static void GoHistory(int value)
     42     {
     43         #region
     44         string js = @"<Script language='JavaScript'>
     45                     history.go({0});  
     46                   </Script>";
     47         HttpContext.Current.Response.Write(string.Format(js, value));
     48         #endregion
     49     }
     50 
     51     /// <summary>
     52     /// 关闭当前窗口
     53     /// </summary>
     54     public static void CloseWindow()
     55     {
     56         #region
     57         string js = @"<Script language='JavaScript'>
     58                     parent.opener=null;window.close();  
     59                   </Script>";
     60         HttpContext.Current.Response.Write(js);
     61         HttpContext.Current.Response.End();
     62         #endregion
     63     }
     64 
     65     /// <summary>
     66     /// 刷新父窗口
     67     /// </summary>
     68     public static void RefreshParent(string url)
     69     {
     70         #region
     71         string js = @"<Script language='JavaScript'>
     72                     window.opener.location.href='" + url + "';window.close();</Script>";
     73         HttpContext.Current.Response.Write(js);
     74         #endregion
     75     }
     76 
     77 
     78     /// <summary>
     79     /// 刷新打开窗口
     80     /// </summary>
     81     public static void RefreshOpener()
     82     {
     83         #region
     84         string js = @"<Script language='JavaScript'>
     85                     opener.location.reload();
     86                   </Script>";
     87         HttpContext.Current.Response.Write(js);
     88         #endregion
     89     }
     90 
     91 
     92     /// <summary>
     93     /// 打开指定大小的新窗体
     94     /// </summary>
     95     /// <param name="url">地址</param>
     96     /// <param name="width"></param>
     97     /// <param name="heigth"></param>
     98     /// <param name="top">头位置</param>
     99     /// <param name="left">左位置</param>
    100     public static void OpenWebFormSize(string url, int width, int heigth, int top, int left)
    101     {
    102         #region
    103         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>";
    104 
    105         HttpContext.Current.Response.Write(js);
    106         #endregion
    107     }
    108 
    109 
    110     /// <summary>
    111     /// 转向Url制定的页面
    112     /// </summary>
    113     /// <param name="url">连接地址</param>
    114     public static void JavaScriptLocationHref(string url)
    115     {
    116         #region
    117         string js = @"<Script language='JavaScript'>
    118                     window.location.replace('{0}');
    119                   </Script>";
    120         js = string.Format(js, url);
    121         HttpContext.Current.Response.Write(js);
    122         #endregion
    123     }
    124 
    125     /// <summary>
    126     /// 打开指定大小位置的模式对话框
    127     /// </summary>
    128     /// <param name="webFormUrl">连接地址</param>
    129     /// <param name="width"></param>
    130     /// <param name="height"></param>
    131     /// <param name="top">距离上位置</param>
    132     /// <param name="left">距离左位置</param>
    133     public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
    134     {
    135         #region
    136         string features = "dialogWidth:" + width.ToString() + "px"
    137             + ";dialogHeight:" + height.ToString() + "px"
    138             + ";dialogLeft:" + left.ToString() + "px"
    139             + ";dialogTop:" + top.ToString() + "px"
    140             + ";center:yes;help=no;resizable:no;status:no;scroll=yes";
    141         ShowModalDialogWindow(webFormUrl, features);
    142         #endregion
    143     }
    144     /// <summary>
    145     /// 弹出模态窗口
    146     /// </summary>
    147     /// <param name="webFormUrl"></param>
    148     /// <param name="features"></param>
    149     public static void ShowModalDialogWindow(string webFormUrl, string features)
    150     {
    151         string js = ShowModalDialogJavascript(webFormUrl, features);
    152         HttpContext.Current.Response.Write(js);
    153     }
    154     /// <summary>
    155     /// 弹出模态窗口
    156     /// </summary>
    157     /// <param name="webFormUrl"></param>
    158     /// <param name="features"></param>
    159     /// <returns></returns>
    160     public static string ShowModalDialogJavascript(string webFormUrl, string features)
    161     {
    162         #region
    163         string js = @"<script language=javascript>                            
    164                             showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
    165         return js;
    166         #endregion
    167     }
    168     #endregion
    169 
    170     #region 新版本
    171     /// <summary>
    172     /// 弹出JavaScript小窗口
    173     /// </summary>
    174     /// <param name="js">窗口信息</param>
    175     public static void Alert(string message, Page page)
    176     {
    177         #region
    178         string js = @"<Script language='JavaScript'>
    179                     alert('" + message + "');</Script>";
    180         //HttpContext.Current.Response.Write(js);
    181         if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "alert"))
    182         {
    183             page.ClientScript.RegisterStartupScript(page.GetType(), "alert", js);
    184         }
    185         #endregion
    186     }
    187 
    188     /// <summary>
    189     /// 弹出消息框并且转向到新的URL
    190     /// </summary>
    191     /// <param name="message">消息内容</param>
    192     /// <param name="toURL">连接地址</param>
    193     public static void AlertAndRedirect(string message, string toURL, Page page)
    194     {
    195         #region
    196         string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
    197         //HttpContext.Current.Response.Write(string.Format(js, message, toURL));
    198         if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "AlertAndRedirect"))
    199         {
    200             page.ClientScript.RegisterStartupScript(page.GetType(), "AlertAndRedirect", string.Format(js, message, toURL));
    201         }
    202         #endregion
    203     }
    204 
    205     /// <summary>
    206     /// 回到历史页面
    207     /// </summary>
    208     /// <param name="value">-1/1</param>
    209     public static void GoHistory(int value, Page page)
    210     {
    211         #region
    212         string js = @"<Script language='JavaScript'>
    213                     history.go({0});  
    214                   </Script>";
    215         //HttpContext.Current.Response.Write(string.Format(js, value));
    216         if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "GoHistory"))
    217         {
    218             page.ClientScript.RegisterStartupScript(page.GetType(), "GoHistory", string.Format(js, value));
    219         }
    220         #endregion
    221     }
    222 
    223     //        /// <summary>
    224     //        /// 关闭当前窗口
    225     //        /// </summary>
    226     //        public static void CloseWindow()
    227     //        {
    228     //            #region
    229     //            string js = @"<Script language='JavaScript'>
    230     //                    parent.opener=null;window.close();  
    231     //                  </Script>";
    232     //            HttpContext.Current.Response.Write(js);
    233     //            HttpContext.Current.Response.End();
    234     //            #endregion
    235     //        }
    236 
    237     /// <summary>
    238     /// 刷新父窗口
    239     /// </summary>
    240     public static void RefreshParent(string url, Page page)
    241     {
    242         #region
    243         string js = @"<Script language='JavaScript'>
    244                     window.opener.location.href='" + url + "';window.close();</Script>";
    245         //HttpContext.Current.Response.Write(js);
    246         if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "RefreshParent"))
    247         {
    248             page.ClientScript.RegisterStartupScript(page.GetType(), "RefreshParent", js);
    249         }
    250         #endregion
    251     }
    252 
    253 
    254     /// <summary>
    255     /// 刷新打开窗口
    256     /// </summary>
    257     public static void RefreshOpener(Page page)
    258     {
    259         #region
    260         string js = @"<Script language='JavaScript'>
    261                     opener.location.reload();
    262                   </Script>";
    263         //HttpContext.Current.Response.Write(js);
    264         if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "RefreshOpener"))
    265         {
    266             page.ClientScript.RegisterStartupScript(page.GetType(), "RefreshOpener", js);
    267         }
    268         #endregion
    269     }
    270 
    271 
    272     /// <summary>
    273     /// 打开指定大小的新窗体
    274     /// </summary>
    275     /// <param name="url">地址</param>
    276     /// <param name="width"></param>
    277     /// <param name="heigth"></param>
    278     /// <param name="top">头位置</param>
    279     /// <param name="left">左位置</param>
    280     public static void OpenWebFormSize(string url, int width, int heigth, int top, int left, Page page)
    281     {
    282         #region
    283         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>";
    284         //HttpContext.Current.Response.Write(js);
    285         if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "OpenWebFormSize"))
    286         {
    287             page.ClientScript.RegisterStartupScript(page.GetType(), "OpenWebFormSize", js);
    288         }
    289         #endregion
    290     }
    291 
    292 
    293     /// <summary>
    294     /// 转向Url制定的页面
    295     /// </summary>
    296     /// <param name="url">连接地址</param>
    297     public static void JavaScriptLocationHref(string url, Page page)
    298     {
    299         #region
    300         string js = @"<Script language='JavaScript'>
    301                     window.location.replace('{0}');
    302                   </Script>";
    303         js = string.Format(js, url);
    304         //HttpContext.Current.Response.Write(js);
    305         if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "JavaScriptLocationHref"))
    306         {
    307             page.ClientScript.RegisterStartupScript(page.GetType(), "JavaScriptLocationHref", js);
    308         }
    309         #endregion
    310     }
    311 
    312     /// <summary>
    313     /// 打开指定大小位置的模式对话框
    314     /// </summary>
    315     /// <param name="webFormUrl">连接地址</param>
    316     /// <param name="width"></param>
    317     /// <param name="height"></param>
    318     /// <param name="top">距离上位置</param>
    319     /// <param name="left">距离左位置</param>
    320     public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left, Page page)
    321     {
    322         #region
    323         string features = "dialogWidth:" + width.ToString() + "px"
    324             + ";dialogHeight:" + height.ToString() + "px"
    325             + ";dialogLeft:" + left.ToString() + "px"
    326             + ";dialogTop:" + top.ToString() + "px"
    327             + ";center:yes;help=no;resizable:no;status:no;scroll=yes";
    328         ShowModalDialogWindow(webFormUrl, features, page);
    329         #endregion
    330     }
    331     /// <summary>
    332     /// 弹出模态窗口
    333     /// </summary>
    334     /// <param name="webFormUrl"></param>
    335     /// <param name="features"></param>
    336     public static void ShowModalDialogWindow(string webFormUrl, string features, Page page)
    337     {
    338         string js = ShowModalDialogJavascript(webFormUrl, features);
    339         //HttpContext.Current.Response.Write(js);
    340         if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), "ShowModalDialogWindow"))
    341         {
    342             page.ClientScript.RegisterStartupScript(page.GetType(), "ShowModalDialogWindow", js);
    343         }
    344     }
    345     //        /// <summary>
    346     //        /// 弹出模态窗口
    347     //        /// </summary>
    348     //        /// <param name="webFormUrl"></param>
    349     //        /// <param name="features"></param>
    350     //        /// <returns></returns>
    351     //        public static string ShowModalDialogJavascript(string webFormUrl, string features)
    352     //        {
    353     //            #region
    354     //            string js = @"<script language=javascript>                            
    355     //    showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
    356     //            return js;
    357     //            #endregion
    358     //        }
    359     #endregion
    360 }
    361 
    362 /// <summary>
    363 /// 一些常用的Js调用
    364 /// 添加新版说明:由于旧版普遍采用Response.Write(string msg)的方式输出js脚本,这种
    365 /// 方式输出的js脚本会在html元素的&lt;html&gt;&lt;/html&gt;标签之外,破坏了整个xhtml的结构,
    366 /// 而新版本则采用ClientScript.RegisterStartupScript(string msg)的方式输出,不会改变xhtml的结构,
    367 /// 不会影响执行效果。
    368 /// 为了向下兼容,所以新版本采用了重载的方式,新版本中要求一个System.Web.UI.Page类的实例。
    代码
      1 using System.Web; 
      2 /// <summary> 
      3 /// Javascript常用方法 
      4 /// </summary> 
      5 public class JS 
      6 { 
      7     private static string ScriptStart = "<script type="text/javascript">"; 
      8     private static string ScriptEnd = "</script>"; 
      9  
     10 
     11     /// <summary> 
     12     /// 写入JS脚本内容 
     13     /// </summary> 
     14     /// <param name="ScriptString">脚本内容</param> 
     15     /// <param name="IsResponseEnd">是否中断服务端脚本执行</param> 
     16     public static void WriteScript(string ScriptString, bool IsResponseEnd) 
     17     { 
     18         HttpContext.Current.Response.Write(ScriptStart); 
     19         HttpContext.Current.Response.Write(ScriptString); 
     20         HttpContext.Current.Response.Write(ScriptEnd); 
     21         if (IsResponseEnd) 
     22         { 
     23             HttpContext.Current.Response.End(); 
     24         } 
     25     } 
     26 
     27    /// <summary> 
     28    /// 弹出警告框 
     29    /// </summary> 
     30    /// <param name="AlertMessage">提示信息</param> 
     31    /// <param name="IsResponseEnd">是否中断服务端脚本执行</param> 
     32     public static void Alert(string AlertMessage, bool IsResponseEnd) 
     33     { 
     34         HttpContext.Current.Response.Write(ScriptStart); 
     35         HttpContext.Current.Response.Write("alert('" + AlertMessage + "');history.back();"); 
     36         HttpContext.Current.Response.Write(ScriptEnd); 
     37         if (IsResponseEnd) 
     38         { 
     39             HttpContext.Current.Response.End(); 
     40         } 
     41     } 
     42 
     43     /// <summary> 
     44     /// 弹出警告框并跳转 
     45     /// </summary> 
     46     /// <param name="AlertMessage">提示信息</param> 
     47     /// <param name="RedirectPath">跳转路径</param> 
     48     /// <param name="IsTopWindow">是否为全屏跳转</param> 
     49     public static void Alert(string AlertMessage, string RedirectPath, bool IsTopWindow) 
     50     { 
     51         HttpContext.Current.Response.Write(ScriptStart); 
     52         HttpContext.Current.Response.Write("alert('" + AlertMessage + "');"); 
     53         if (IsTopWindow) 
     54         { 
     55             HttpContext.Current.Response.Write("parent.top.location.href='" + RedirectPath + "';"); 
     56         } 
     57         else 
     58         { 
     59             HttpContext.Current.Response.Write("location.href='" + RedirectPath + "';"); 
     60         } 
     61         HttpContext.Current.Response.Write(ScriptEnd); 
     62         HttpContext.Current.Response.End(); 
     63     } 
     64 
     65     /// <summary> 
     66     /// 弹出警告框并关闭窗口 
     67     /// </summary> 
     68     /// <param name="AlertMessage">提示信息</param> 
     69     public static void AlertAndClose(string AlertMessage) 
     70     { 
     71         HttpContext.Current.Response.Write(ScriptStart); 
     72         HttpContext.Current.Response.Write("alert('" + AlertMessage + "');window.close();"); 
     73         HttpContext.Current.Response.Write(ScriptEnd); 
     74         HttpContext.Current.Response.End(); 
     75     } 
     76 
     77     /// <summary> 
     78     /// 全屏跳转 
     79     /// </summary> 
     80     /// <param name="RedirectpPath">跳转路径</param> 
     81     public static void TopRedirect(string RedirectpPath) 
     82     { 
     83         HttpContext.Current.Response.Write(ScriptStart); 
     84         HttpContext.Current.Response.Write("parent.top.location.href='" + RedirectpPath + "';"); 
     85         HttpContext.Current.Response.Write(ScriptEnd); 
     86         HttpContext.Current.Response.End(); 
     87     } 
     88 
     89     /// <summary> 
     90     /// 判断并跳转 
     91     /// </summary> 
     92     /// <param name="confirmMessage">提示信息</param> 
     93     /// <param name="YesRedirectPath">选择“是”后跳转的路径</param> 
     94     /// <param name="NoRedirectPath">选择“否”后跳转的路径</param> 
     95     /// <param name="IsResponseEnd">是否中断服务端脚本执行</param> 
     96     public static void ConfirmRedirect(string confirmMessage, string YesRedirectPath, string NoRedirectPath, bool IsResponseEnd) 
     97     { 
     98         HttpContext.Current.Response.Write(ScriptStart); 
     99         HttpContext.Current.Response.Write("if(confirm('" + confirmMessage + "')){location.href='" + YesRedirectPath + "';}else{location.href='" + NoRedirectPath + "';}"); 
    100         HttpContext.Current.Response.Write(ScriptEnd); 
    101         if (IsResponseEnd) 
    102         { 
    103             HttpContext.Current.Response.End(); 
    104         } 
    105     } 
    106 
    107     /// <summary> 
    108     /// 判断并写入脚本代码 
    109     /// </summary> 
    110     /// <param name="confirmMessage">提示信息</param> 
    111     /// <param name="YesScript">选择“是”后写入的脚本内容</param> 
    112     /// <param name="NoScript">选择“否”后写入的脚本内容</param> 
    113     /// <param name="IsResponseEnd">是否中断服务端脚本执行</param> 
    114     public static void ConfirmScript(string confirmMessage, string YesScript, string NoScript, bool IsResponseEnd) 
    115     { 
    116         HttpContext.Current.Response.Write(ScriptStart); 
    117         HttpContext.Current.Response.Write("if(confirm('" + confirmMessage + "')){" + YesScript + "}else{" + NoScript + "}"); 
    118         HttpContext.Current.Response.Write(ScriptEnd); 
    119         if (IsResponseEnd) 
    120         { 
    121             HttpContext.Current.Response.End(); 
    122         } 
    123     } 
    124 
    125 }
    代码
      1 using System;
      2 using System.Data;
      3 using System.Configuration;
      4 using System.Web;
      5 using System.Web.Security;
      6 using System.Web.UI;
      7 using System.Web.UI.WebControls;
      8 using System.Web.UI.WebControls.WebParts;
      9 using System.Web.UI.HtmlControls;
     10 
     11 namespace WebApplication3
     12 {
     13 
     14 
     15     /// <summary>
     16     /// javascript弹出窗口封装类
     17     /// </summary>
     18     public static class JSCommon
     19     {
     20         /// <summary>
     21         /// 显示消息提示对话框
     22         /// </summary>
     23         /// <param name="page">当前页面指针,一般为"this"</param>
     24         /// <param name="msg">提示信息</param>
     25         public static void ShowAlert(System.Web.UI.Page page, string msg)
     26         {
     27             System.Text.StringBuilder Builder = new System.Text.StringBuilder();
     28             Builder.Append("<script language='javascript' defer>");
     29             Builder.AppendFormat("alert('{0}');", msg);
     30             Builder.Append("</script>");
     31             page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
     32         }
     33         /// <summary>
     34         /// 打开大小不可变模式窗口
     35         /// </summary>
     36         /// <param name="page">当前页面指针,一般为"this"</param>
     37         /// <param name="PageUrl">打开的模式窗口显示的网页地址</param>
     38         /// <param name="Width">打开的模式窗口的宽度</param>
     39         /// <param name="Height">打开的模式窗口的高度</param>
     40         public static void OpenFixModalDialog(System.Web.UI.Page page, String PageUrl, int Width, int Height)
     41         {
     42             System.Text.StringBuilder Builder = new System.Text.StringBuilder();
     43             Builder.Append("<script language='javascript' defer>");
     44             Builder.AppendFormat("window.showModalDialog('{0}',null,'dialogWidth:{1}px;dialogHeight:{2}px;help:no;unadorned:no;resizable:no;status:no');", PageUrl, Width, Height);
     45             Builder.Append("</script>");
     46             page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
     47         }
     48         /// <summary>
     49         /// 打开大小可变模式窗口
     50         /// </summary>
     51         /// <param name="page">当前页面指针,一般为"this"</param>
     52         /// <param name="PageUrl">打开的模式窗口显示的网页地址</param>
     53         /// <param name="Width">打开的模式窗口的宽度</param>
     54         /// <param name="Height">打开的模式窗口的高度</param>
     55         public static void OpenSizeableModalDialog(System.Web.UI.Page page, String PageUrl, int Width, int Height)
     56         {
     57             System.Text.StringBuilder Builder = new System.Text.StringBuilder();
     58             Builder.Append("<script language='javascript' defer>");
     59             Builder.AppendFormat("window.showModalDialog('{0}',null,'dialogWidth:{1}px;dialogHeight:{2}px;help:no;unadorned:no;resizable:yes;status:no');", PageUrl, Width, Height);
     60             Builder.Append("</script>");
     61             page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
     62         }
     63         /// <summary>
     64         /// 打开悬浮提示窗口
     65         /// </summary>
     66         /// <param name="page">页面指针 一般输入"this"</param>
     67         /// <param name="message">显示的消息</param>
     68         /// <param name="Width">窗口宽度</param>
     69         /// <param name="height">窗口高度</param>
     70         public static void OpenFloatDialog(System.Web.UI.Page page, string message, int Width, int height)
     71         {
     72             System.Text.StringBuilder Builder = new System.Text.StringBuilder();
     73             Builder.Append("<script type='text/javascript' language='javascript' defer>");
     74             //   Builder.Append("var msgw,msgh,bordercolor; ");
     75             Builder.AppendLine("function ShowBDDialog(){ ");
     76             Builder.AppendLine("bordercolor='#66ccff';titlecolor='#99CCFF';");
     77             Builder.AppendLine("var sWidth,sHeight; sWidth=document.body.offsetWidth; sHeight=document.body.offsetHeight;");
     78             Builder.AppendLine("var bgObj=document.createElement('div'); ");
     79             Builder.AppendLine(" bgObj.setAttribute('id','bgDiv'); ");
     80             Builder.AppendLine("bgObj.style.position='absolute'; ");
     81             Builder.AppendLine("bgObj.style.top='0'; bgObj.style.background='#dcdcdc';");
     82             Builder.AppendLine("bgObj.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75';");
     83             Builder.AppendLine("bgObj.style.opacity='0.6'; ");
     84             Builder.AppendLine("bgObj.style.left='0';");
     85             Builder.AppendLine("bgObj.style.width=sWidth + 'px'; ");
     86             Builder.AppendLine("bgObj.style.height=sHeight + 'px';");
     87             Builder.AppendLine("document.body.appendChild(bgObj); ");
     88             Builder.AppendLine("var msgObj=document.createElement('div')");
     89             Builder.AppendLine("msgObj.setAttribute('id','msgDiv');");
     90             Builder.AppendLine("msgObj.setAttribute('align','center');");
     91             Builder.AppendLine("msgObj.style.position='absolute';msgObj.style.background='white'; ");
     92             Builder.AppendLine("msgObj.style.font='12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif';");
     93             Builder.AppendLine("msgObj.style.border='1px solid ' + bordercolor;");
     94             Builder.AppendFormat("msgObj.style.width='{0} '+ 'px'; ", Width);
     95             Builder.AppendFormat("msgObj.style.height='{0}' + 'px';", height);
     96             Builder.AppendFormat("msgObj.style.top=(document.documentElement.scrollTop + (sHeight-'{0}')/2) + 'px';", height);
     97             Builder.AppendFormat("msgObj.style.left=(sWidth-'{0}')/2 + 'px';", Width);
     98             Builder.AppendLine("var title=document.createElement('h4');");
     99             Builder.AppendLine("title.setAttribute('id','msgTitle');");
    100             Builder.AppendLine("title.setAttribute('align','right');");
    101             Builder.AppendLine("title.style.margin='0'; ");
    102             Builder.AppendLine("title.style.padding='3px'; title.style.background=bordercolor; ");
    103             Builder.AppendLine("title.style.filter='progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);'; ");
    104             Builder.AppendLine("title.style.opacity='0.75'; ");
    105             Builder.AppendLine("title.style.border='1px solid ' + bordercolor;title.innerHTML='<a style=font-size:small href=#>关闭</a>'; ");
    106             Builder.AppendLine("title.onclick=function(){ document.body.removeChild(bgObj);document.getElementById('msgDiv').removeChild(title); document.body.removeChild(msgObj);} ");
    107             Builder.AppendLine("document.body.appendChild(msgObj); ");
    108             Builder.AppendLine("document.getElementById('msgDiv').appendChild(title);");
    109             Builder.AppendLine("var txt=document.createElement('p');");
    110             Builder.AppendFormat("txt.style.height='{0}';", height);
    111             Builder.AppendFormat("txt.style.width='{0}';", Width);
    112             Builder.AppendLine(" txt.style.margin='1em 0' ");
    113             Builder.AppendLine("txt.setAttribute('id','msgTxt');");
    114             Builder.AppendFormat("txt.innerHTML='{0}'; ", message);
    115             Builder.AppendLine("document.getElementById('msgDiv').appendChild(txt);return false;}");
    116             Builder.AppendLine(" ShowBDDialog(); </script>");
    117             page.Response.Write(Builder.ToString());
    118             page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javscript'>ShowBDDialog();</" + "script>");
    119         }
    120         /// <summary>
    121         /// 打开悬浮弹出窗口
    122         /// </summary>
    123         /// <param name="page">页面指针 一般输入"this"</param>
    124         /// <param name="url">打开的页面的url</param>
    125         /// <param name="Width">窗口宽度</param>
    126         /// <param name="height">窗口高度</param>
    127         public static void OpenFloatModalWindow(System.Web.UI.Page page, string url, int Width, int height)
    128         {
    129             System.Text.StringBuilder Builder = new System.Text.StringBuilder();
    130             Builder.Append("<script type='text/javascript' language='javascript' defer>");
    131             //   Builder.Append("var msgw,msgh,bordercolor; ");
    132             Builder.AppendLine("function ShowBDDialog(){ ");
    133             Builder.AppendLine("bordercolor='#66ccff';titlecolor='#99CCFF';");
    134             Builder.AppendLine("var sWidth,sHeight; sWidth=document.body.offsetWidth; sHeight=document.body.offsetHeight;");
    135             Builder.AppendLine("var bgObj=document.createElement('div'); ");
    136             Builder.AppendLine(" bgObj.setAttribute('id','bgDiv'); ");
    137             Builder.AppendLine("bgObj.style.position='absolute'; ");
    138             Builder.AppendLine("bgObj.style.top='0'; bgObj.style.background='#dcdcdc';");
    139             Builder.AppendLine("bgObj.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75';");
    140             Builder.AppendLine("bgObj.style.opacity='0.6'; ");
    141             Builder.AppendLine("bgObj.style.left='0';");
    142             Builder.AppendLine("bgObj.style.width=sWidth + 'px'; ");
    143             Builder.AppendLine("bgObj.style.height=sHeight + 'px';");
    144             Builder.AppendLine("document.body.appendChild(bgObj); ");
    145             Builder.AppendLine("var msgObj=document.createElement('div')");
    146             Builder.AppendLine("msgObj.setAttribute('id','msgDiv');");
    147             Builder.AppendLine("msgObj.setAttribute('align','center');");
    148             Builder.AppendLine("msgObj.style.position='absolute';msgObj.style.background='white'; ");
    149             Builder.AppendLine("msgObj.style.font='12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif';");
    150             Builder.AppendLine("msgObj.style.border='1px solid ' + bordercolor;");
    151             Builder.AppendFormat("msgObj.style.width='{0} '+ 'px'; ", Width);
    152             Builder.AppendFormat("msgObj.style.height='{0}' + 'px';", height);
    153             Builder.AppendFormat("msgObj.style.top=(document.documentElement.scrollTop + (sHeight-'{0}')/2) + 'px';", height);
    154             Builder.AppendFormat("msgObj.style.left=(sWidth-'{0}')/2 + 'px';", Width);
    155             Builder.AppendLine("var title=document.createElement('h4');");
    156             Builder.AppendLine("title.setAttribute('id','msgTitle');");
    157             Builder.AppendLine("title.setAttribute('align','right');");
    158             Builder.AppendLine("title.style.margin='0'; ");
    159             Builder.AppendLine("title.style.padding='3px'; title.style.background=bordercolor; ");
    160             Builder.AppendLine("title.style.filter='progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);'; ");
    161             Builder.AppendLine("title.style.opacity='0.75'; ");
    162             Builder.AppendLine("title.style.border='1px solid ' + bordercolor;title.innerHTML='<a style=font-size:small href=#>关闭</a>'; ");
    163             Builder.AppendLine("title.onclick=function(){ document.body.removeChild(bgObj);document.getElementById('msgDiv').removeChild(title); document.body.removeChild(msgObj);} ");
    164             Builder.AppendLine("document.body.appendChild(msgObj); ");
    165             Builder.AppendLine("document.getElementById('msgDiv').appendChild(title);");
    166             Builder.AppendLine("var txt=document.createElement('iframe');");
    167             Builder.AppendFormat("txt.style.height='{0}';", height);
    168             Builder.AppendFormat("txt.style.width='{0}';", Width);
    169             Builder.AppendLine(" txt.style.margin='1em 0' ");
    170             Builder.AppendLine("txt.setAttribute('id','msgTxt');");
    171             Builder.AppendFormat("txt.src='{0}'; ", url);
    172             Builder.AppendLine("document.getElementById('msgDiv').appendChild(txt);return false;}");
    173             Builder.AppendLine(" ShowBDDialog(); </script>");
    174             page.Response.Write(Builder.ToString());
    175             page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javscript'>ShowBDDialog();</" + "script>");
    176         }
    177     }
    178 }
    代码

    ***********************************************************************************************
    *【Author】:无意创新
    *【Date】:2013年07月17日
    *【URL】:http://www.cnblogs.com/getsound/archive/2010/09/01/1814833.html
    *【Notice】:
    *1、本文为原创技术文章,首发博客园个人站点。
    *2、转载和引用请注明作者及出处。
    *3、本文必须全文转载和引用,任何组织和个人未授权不能修改任何内容,并且未授权不可用于商业。
    *4、本声明为文章一部分,转载和引用必须包括在原文中。
    ***********************************************************************************************

  • 相关阅读:
    去掉FALSH背景的代码
    问一个比较傻瓜的问题关于 this.TextBox1.Visible = true;
    网页防止复制 下载 另存为的JS
    [转] left join/right join/inner join操作演示
    VS2003新起项目步骤
    我专严新闻小偷之心得与大家交流
    ACCESS数据库里SQL语句的3个表联合,和SQL有很大差别
    vs2005常用快捷键
    NoSql中的CAP分类【转载】
    epoll用法【整理】
  • 原文地址:https://www.cnblogs.com/armyant/p/3196160.html
Copyright © 2020-2023  润新知