| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- using System;
- using System.Web;
- using System.Web.UI;
- namespace Common
- {
- public class JScript
- {
- 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));
- }
- public static void AlertAndReturnValueToParent(string message, string jsStr)
- {
- string js = "<script language=javascript>alert('{0}');{1}</script>";
- HttpContext.Current.Response.Write(string.Format(js, message, jsStr));
- }
- public void JscriptSender(Page page)
- {
- page.ClientScript.RegisterHiddenField("__EVENTTARGET", "");
- page.ClientScript.RegisterHiddenField("__EVENTARGUMENT", "");
- string s = "\t\t\r\n<script language=Javascript>\r\n function KendoPostBack(eventTarget, eventArgument) \r\n {\r\n\t\t\t\tvar theform = document.forms[0];\r\n\t\t\t\ttheform.__EVENTTARGET.value = eventTarget;\r\n\t\t\t\ttheform.__EVENTARGUMENT.value = eventArgument;\r\n\t\t\t\ttheform.submit();\r\n\t\t\t}\r\n</script>";
- page.ClientScript.RegisterStartupScript(base.GetType(), "sds", s);
- }
- public static void Alert(string message)
- {
- message = StringUtil.DeleteUnVisibleChar(message);
- string js = "<Script language='JavaScript'>\r\n alert('" + message + "');</Script>";
- HttpContext.Current.Response.Write(js);
- }
- public static void Alert(object message)
- {
- string js = "<Script language='JavaScript'>\r\n alert('{0}'); \r\n </Script>";
- HttpContext.Current.Response.Write(string.Format(js, message.ToString()));
- }
- public static void RtnRltMsgbox(object message, string strWinCtrl)
- {
- string js = "<Script language='JavaScript'>\r\n\t\t\t\t\t strWinCtrl = true;\r\n strWinCtrl = if(!confirm('" + message + "'))return false;</Script>";
- HttpContext.Current.Response.Write(string.Format(js, message.ToString()));
- }
- public static void GoHistory(int value)
- {
- string js = "<Script language='JavaScript'>\r\n history.go({0}); \r\n </Script>";
- HttpContext.Current.Response.Write(string.Format(js, value));
- }
- public static void CloseWindow()
- {
- string js = "<Script language='JavaScript'>\r\n window.close(); \r\n </Script>";
- HttpContext.Current.Response.Write(js);
- HttpContext.Current.Response.End();
- }
- public static void RefreshParent()
- {
- string js = "<Script language='JavaScript'>\r\n parent.location.reload();\r\n </Script>";
- HttpContext.Current.Response.Write(js);
- }
- public static string JSStringFormat(string s)
- {
- return s.Replace("\r", "\\r").Replace("\n", "\\n").Replace("'", "\\'").Replace("\"", "\\\"");
- }
- public static void RefreshOpener()
- {
- string js = "<Script language='JavaScript'>\r\n opener.location.reload();\r\n </Script>";
- HttpContext.Current.Response.Write(js);
- }
- public static void OpenWebForm(string url)
- {
- string js = string.Concat(new string[]
- {
- "<Script language='JavaScript'>\r\n\t\t\t//window.open('",
- url,
- "');\r\n\t\t\twindow.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');\r\n\t\t\t</Script>"
- });
- HttpContext.Current.Response.Write(js);
- }
- public static void OpenWebForm(string url, string name, string future)
- {
- string js = string.Concat(new string[]
- {
- "<Script language='JavaScript'>\r\n window.open('",
- url,
- "','",
- name,
- "','",
- future,
- "')\r\n </Script>"
- });
- HttpContext.Current.Response.Write(js);
- }
- public static void OpenWebForm(string url, string formName)
- {
- string js = string.Concat(new string[]
- {
- "<Script language='JavaScript'>\r\n\t\t\t//window.open('",
- url,
- "','",
- formName,
- "');\r\n\t\t\twindow.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');\r\n\t\t\t</Script>"
- });
- HttpContext.Current.Response.Write(js);
- }
- 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 = js + "window.open('" + url + "','',szFeatures);";
- }
- else
- {
- js = 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);
- }
- public static void JavaScriptLocationHref(string url)
- {
- string js = "<Script language='JavaScript'>\r\n window.location.replace('{0}');\r\n </Script>";
- js = string.Format(js, url);
- HttpContext.Current.Response.Write(js);
- }
- public static void JavaScriptFrameHref(string FrameName, string url)
- {
- string js = "<Script language='JavaScript'>\r\n\t\t\t\t\t\r\n @obj.location.replace(\"{0}\");\r\n </Script>";
- js = js.Replace("@obj", FrameName);
- js = string.Format(js, url);
- HttpContext.Current.Response.Write(js);
- }
- public static void JavaScriptResetPage(string strRows)
- {
- string js = "<Script language='JavaScript'>\r\n window.parent.CenterFrame.rows='" + strRows + "';</Script>";
- HttpContext.Current.Response.Write(js);
- }
- public static void JavaScriptSetCookie(string strName, string strValue)
- {
- string js = string.Concat(new string[]
- {
- "<script language=Javascript>\r\n\t\t\tvar the_cookie = '",
- strName,
- "=",
- strValue,
- "'\r\n\t\t\tvar dateexpire = 'Tuesday, 01-Dec-2020 12:00:00 GMT';\r\n\t\t\t//document.cookie = the_cookie;//写入Cookie<BR>} <BR>\r\n\t\t\tdocument.cookie = the_cookie + '; expires='+dateexpire;\t\t\t\r\n\t\t\t</script>"
- });
- HttpContext.Current.Response.Write(js);
- }
- public static void GotoParentWindow(string parentWindowUrl)
- {
- string js = "<Script language='JavaScript'>\r\n this.parent.location.replace('" + parentWindowUrl + "');</Script>";
- HttpContext.Current.Response.Write(js);
- }
- public static void ReplaceParentWindow(string parentWindowUrl, string caption, string future)
- {
- string js;
- if (future != null && future.Trim() != "")
- {
- js = string.Concat(new string[]
- {
- "<script language=javascript>this.parent.location.replace('",
- parentWindowUrl,
- "','",
- caption,
- "','",
- future,
- "');</script>"
- });
- }
- else
- {
- js = string.Concat(new string[]
- {
- "<script language=javascript>var iWidth = 0 ;var iHeight = 0 ;iWidth=window.screen.availWidth-10;iHeight=window.screen.availHeight-50;\r\n\t\t\t\t\t\t\tvar szFeatures = 'dialogWidth:'+iWidth+';dialogHeight:'+iHeight+';dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes';this.parent.location.replace('",
- parentWindowUrl,
- "','",
- caption,
- "',szFeatures);</script>"
- });
- }
- HttpContext.Current.Response.Write(js);
- }
- public static void ReplaceOpenerWindow(string openerWindowUrl)
- {
- string js = "<Script language='JavaScript'>\r\n window.opener.location.replace('" + openerWindowUrl + "');</Script>";
- HttpContext.Current.Response.Write(js);
- }
- public static void ReplaceOpenerParentFrame(string frameName, string frameWindowUrl)
- {
- string js = string.Concat(new string[]
- {
- "<Script language='JavaScript'>\r\n window.opener.parent.",
- frameName,
- ".location.replace('",
- frameWindowUrl,
- "');</Script>"
- });
- HttpContext.Current.Response.Write(js);
- }
- public static void ReplaceOpenerParentWindow(string openerParentWindowUrl)
- {
- string js = "<Script language='JavaScript'>\r\n window.opener.parent.location.replace('" + openerParentWindowUrl + "');</Script>";
- HttpContext.Current.Response.Write(js);
- }
- public static void CloseParentWindow()
- {
- string js = "<Script language='JavaScript'>\r\n window.parent.close(); \r\n </Script>";
- HttpContext.Current.Response.Write(js);
- }
- public static void CloseOpenerWindow()
- {
- string js = "<Script language='JavaScript'>\r\n window.opener.close(); \r\n </Script>";
- HttpContext.Current.Response.Write(js);
- }
- public static string ShowModalDialogJavascript(string webFormUrl)
- {
- return "<script language=javascript>\r\n\t\t\t\t\t\t\tvar iWidth = 0 ;\r\n\t\t\t\t\t\t\tvar iHeight = 0 ;\r\n\t\t\t\t\t\t\tiWidth=window.screen.availWidth-10;\r\n\t\t\t\t\t\t\tiHeight=window.screen.availHeight-50;\r\n\t\t\t\t\t\t\tvar szFeatures = 'dialogWidth:'+iWidth+';dialogHeight:'+iHeight+';dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes';\r\n\t\t\t\t\t\t\tshowModalDialog('" + webFormUrl + "','',szFeatures);</script>";
- }
- public static string ShowModalDialogJavascript(string webFormUrl, string features)
- {
- return string.Concat(new string[]
- {
- "<script language=javascript>\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\tshowModalDialog('",
- webFormUrl,
- "','','",
- features,
- "');</script>"
- });
- }
- public static void ShowModalDialogWindow(string webFormUrl)
- {
- string js = JScript.ShowModalDialogJavascript(webFormUrl);
- HttpContext.Current.Response.Write(js);
- }
- public static void ShowModalDialogWindow(string webFormUrl, string features)
- {
- string js = JScript.ShowModalDialogJavascript(webFormUrl, features);
- HttpContext.Current.Response.Write(js);
- }
- public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
- {
- string features = string.Concat(new string[]
- {
- "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"
- });
- JScript.ShowModalDialogWindow(webFormUrl, features);
- }
- public static void SetHtmlElementValue(string formName, string elementName, string elementValue)
- {
- string js = string.Concat(new string[]
- {
- "<Script language='JavaScript'>if(document.",
- formName,
- ".",
- elementName,
- "!=null){document.",
- formName,
- ".",
- elementName,
- ".value =",
- elementValue,
- ";}</Script>"
- });
- HttpContext.Current.Response.Write(js);
- }
- }
- }
|