1
using
System;
2 using System.Web;
3 using System.Web.UI;
4
5 namespace COCOWO.COMP
6 {
7 /**//**//**//// <summary>
8 /// 一些常用的Js调用
9 /// 创建时间:2006-8-3
10 /// 创建者:马先光
11 /// </summary>
12 public class Jscript
13 {
14
15 /**//**//**//// <summary>
16 /// 弹出JavaScript小窗口
17 /// </summary>
18 /// <param name="js">窗口信息</param>
19 public static void Alert(string message)
20 {
21 #region
22 string js = @"<Script language='JavaScript'>
23 alert('" + message + "');</Script>";
24 HttpContext.Current.Response.Write(js);
25 #endregion
26 }
27
28 /**//**//**//// <summary>
29 /// 弹出消息框并且转向到新的URL
30 /// </summary>
31 /// <param name="message">消息内容</param>
32 /// <param name="toURL">连接地址</param>
33 public static void AlertAndRedirect(string message, string toURL)
34 {
35 #region
36 string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
37 HttpContext.Current.Response.Write(string.Format(js, message, toURL));
38 #endregion
39 }
40
41 /**//**//**//// <summary>
42 /// 回到历史页面
43 /// </summary>
44 /// <param name="value">-1/1</param>
45 public static void GoHistory(int value)
46 {
47 #region
48 string js = @"<Script language='JavaScript'>
49 history.go({0});
50 </Script>";
51 HttpContext.Current.Response.Write(string.Format(js, value));
52 #endregion
53 }
54
55 /**//**//**//// <summary>
56 /// 关闭当前窗口
57 /// </summary>
58 public static void CloseWindow()
59 {
60 #region
61 string js = @"<Script language='JavaScript'>
62 parent.opener=null;window.close();
63 </Script>";
64 HttpContext.Current.Response.Write(js);
65 HttpContext.Current.Response.End();
66 #endregion
67 }
68
69 /**//**//**//// <summary>
70 /// 刷新父窗口
71 /// </summary>
72 public static void RefreshParent(string url)
73 {
74 #region
75 string js = @"<script>try{top.location="""+url+@"""}catch(e){location="""+url+@"""}</script>";
76 HttpContext.Current.Response.Write(js);
77 #endregion
78 }
79
80
81 /**//**//**//// <summary>
82 /// 刷新打开窗口
83 /// </summary>
84 public static void RefreshOpener()
85 {
86 #region
87 string js = @"<Script language='JavaScript'>
88 opener.location.reload();
89 </Script>";
90 HttpContext.Current.Response.Write(js);
91 #endregion
92 }
93
94
95 /**//**//**//// <summary>
96 /// 打开指定大小的新窗体
97 /// </summary>
98 /// <param name="url">地址</param>
99 /// <param name="width">宽</param>
100 /// <param name="heigth">高</param>
101 /// <param name="top">头位置</param>
102 /// <param name="left">左位置</param>
103 public static void OpenWebFormSize(string url, int width,int heigth,int top,int left)
104 {
105 #region
106 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>";
107
108 HttpContext.Current.Response.Write(js);
109 #endregion
110 }
111
112
113 /**//**//**//// <summary>
114 /// 转向Url制定的页面
115 /// </summary>
116 /// <param name="url">连接地址</param>
117 public static void JavaScriptLocationHref(string url)
118 {
119 #region
120 string js = @"<Script language='JavaScript'>
121 window.location.replace('{0}');
122 </Script>";
123 js = string.Format(js, url);
124 HttpContext.Current.Response.Write(js);
125 #endregion
126 }
127
128 /**//**//**//// <summary>
129 /// 打开指定大小位置的模式对话框
130 /// </summary>
131 /// <param name="webFormUrl">连接地址</param>
132 /// <param name="width">宽</param>
133 /// <param name="height">高</param>
134 /// <param name="top">距离上位置</param>
135 /// <param name="left">距离左位置</param>
136 public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
137 {
138 #region
139 string features = "dialogWidth:" + width.ToString() + "px"
140 + ";dialogHeight:" + height.ToString() + "px"
141 + ";dialogLeft:" + left.ToString() + "px"
142 + ";dialogTop:" + top.ToString() + "px"
143 + ";center:yes;help=no;resizable:no;status:no;scroll=yes";
144 ShowModalDialogWindow(webFormUrl, features);
145 #endregion
146 }
147
148 public static void ShowModalDialogWindow(string webFormUrl, string features)
149 {
150 string js = ShowModalDialogJavascript(webFormUrl, features);
151 HttpContext.Current.Response.Write(js);
152 }
153
154 public static string ShowModalDialogJavascript(string webFormUrl, string features)
155 {
156 #region
157 string js = @"<script language=javascript>
158 showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
159 return js;
160 #endregion
161 }
162
163
164 }
165}
166
2 using System.Web;
3 using System.Web.UI;
4
5 namespace COCOWO.COMP
6 {
7 /**//**//**//// <summary>
8 /// 一些常用的Js调用
9 /// 创建时间:2006-8-3
10 /// 创建者:马先光
11 /// </summary>
12 public class Jscript
13 {
14
15 /**//**//**//// <summary>
16 /// 弹出JavaScript小窗口
17 /// </summary>
18 /// <param name="js">窗口信息</param>
19 public static void Alert(string message)
20 {
21 #region
22 string js = @"<Script language='JavaScript'>
23 alert('" + message + "');</Script>";
24 HttpContext.Current.Response.Write(js);
25 #endregion
26 }
27
28 /**//**//**//// <summary>
29 /// 弹出消息框并且转向到新的URL
30 /// </summary>
31 /// <param name="message">消息内容</param>
32 /// <param name="toURL">连接地址</param>
33 public static void AlertAndRedirect(string message, string toURL)
34 {
35 #region
36 string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
37 HttpContext.Current.Response.Write(string.Format(js, message, toURL));
38 #endregion
39 }
40
41 /**//**//**//// <summary>
42 /// 回到历史页面
43 /// </summary>
44 /// <param name="value">-1/1</param>
45 public static void GoHistory(int value)
46 {
47 #region
48 string js = @"<Script language='JavaScript'>
49 history.go({0});
50 </Script>";
51 HttpContext.Current.Response.Write(string.Format(js, value));
52 #endregion
53 }
54
55 /**//**//**//// <summary>
56 /// 关闭当前窗口
57 /// </summary>
58 public static void CloseWindow()
59 {
60 #region
61 string js = @"<Script language='JavaScript'>
62 parent.opener=null;window.close();
63 </Script>";
64 HttpContext.Current.Response.Write(js);
65 HttpContext.Current.Response.End();
66 #endregion
67 }
68
69 /**//**//**//// <summary>
70 /// 刷新父窗口
71 /// </summary>
72 public static void RefreshParent(string url)
73 {
74 #region
75 string js = @"<script>try{top.location="""+url+@"""}catch(e){location="""+url+@"""}</script>";
76 HttpContext.Current.Response.Write(js);
77 #endregion
78 }
79
80
81 /**//**//**//// <summary>
82 /// 刷新打开窗口
83 /// </summary>
84 public static void RefreshOpener()
85 {
86 #region
87 string js = @"<Script language='JavaScript'>
88 opener.location.reload();
89 </Script>";
90 HttpContext.Current.Response.Write(js);
91 #endregion
92 }
93
94
95 /**//**//**//// <summary>
96 /// 打开指定大小的新窗体
97 /// </summary>
98 /// <param name="url">地址</param>
99 /// <param name="width">宽</param>
100 /// <param name="heigth">高</param>
101 /// <param name="top">头位置</param>
102 /// <param name="left">左位置</param>
103 public static void OpenWebFormSize(string url, int width,int heigth,int top,int left)
104 {
105 #region
106 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>";
107
108 HttpContext.Current.Response.Write(js);
109 #endregion
110 }
111
112
113 /**//**//**//// <summary>
114 /// 转向Url制定的页面
115 /// </summary>
116 /// <param name="url">连接地址</param>
117 public static void JavaScriptLocationHref(string url)
118 {
119 #region
120 string js = @"<Script language='JavaScript'>
121 window.location.replace('{0}');
122 </Script>";
123 js = string.Format(js, url);
124 HttpContext.Current.Response.Write(js);
125 #endregion
126 }
127
128 /**//**//**//// <summary>
129 /// 打开指定大小位置的模式对话框
130 /// </summary>
131 /// <param name="webFormUrl">连接地址</param>
132 /// <param name="width">宽</param>
133 /// <param name="height">高</param>
134 /// <param name="top">距离上位置</param>
135 /// <param name="left">距离左位置</param>
136 public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
137 {
138 #region
139 string features = "dialogWidth:" + width.ToString() + "px"
140 + ";dialogHeight:" + height.ToString() + "px"
141 + ";dialogLeft:" + left.ToString() + "px"
142 + ";dialogTop:" + top.ToString() + "px"
143 + ";center:yes;help=no;resizable:no;status:no;scroll=yes";
144 ShowModalDialogWindow(webFormUrl, features);
145 #endregion
146 }
147
148 public static void ShowModalDialogWindow(string webFormUrl, string features)
149 {
150 string js = ShowModalDialogJavascript(webFormUrl, features);
151 HttpContext.Current.Response.Write(js);
152 }
153
154 public static string ShowModalDialogJavascript(string webFormUrl, string features)
155 {
156 #region
157 string js = @"<script language=javascript>
158 showModalDialog('" + webFormUrl + "','','" + features + "');</script>";
159 return js;
160 #endregion
161 }
162
163
164 }
165}
166