Nenhuma Descrição

JScript.cs 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System.Web;
  2. namespace CallCenter.Utility
  3. {
  4. /// <summary>
  5. /// JScript 的摘要说明
  6. /// 在开发过程中可以用的一些技巧文件
  7. ///本js也是从别的oa中提取来的
  8. /// </summary>
  9. public static class Jscript
  10. {
  11. /// <summary>
  12. /// 弹出JavaScript小窗口,并转向指定的页面
  13. /// </summary>
  14. /// <param name="message">弹出信息</param>
  15. /// <param name="toURL">专转向的网页</param>
  16. public static void AlertAndRedirect(string message, string toURL)
  17. {
  18. string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
  19. HttpContext.Current.Response.Write(string.Format(js, message, toURL));
  20. HttpContext.Current.Response.End();
  21. }
  22. /// <summary>
  23. /// 弹出JavaScript小窗口,并转向来源页
  24. /// </summary>
  25. /// <param name="message">弹出信息</param>
  26. public static void AlertAndRedirect(string message)
  27. {
  28. string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
  29. HttpContext.Current.Response.Write(string.Format(js, message, HttpContext.Current.Request.RawUrl));
  30. HttpContext.Current.Response.End();
  31. }
  32. /// <summary>
  33. /// 弹出JavaScript小窗口,并向父页转向指定的页面
  34. /// </summary>
  35. /// <param name="message">弹出信息</param>
  36. /// <param name="toURL">转向的网页</param>
  37. public static void AlertAndRedirectTop(string message, string toURL)
  38. {
  39. string js = "<script language=javascript>alert('{0}');window.top.location.replace('{1}')</script>";
  40. HttpContext.Current.Response.Write(string.Format(js, message, toURL));
  41. HttpContext.Current.Response.End();
  42. }
  43. /// <summary>
  44. /// 弹出JavaScript是/否小窗口,并转向指定的页面
  45. /// </summary>
  46. /// <param name="message">弹出是/否信息</param>
  47. /// <param name="YESURL">是:转向的网页</param>
  48. /// <param name="NOURL">否:转向的网页</param>
  49. public static void confirm(string message, string YESURL, string NOURL)
  50. {
  51. string js = "<script language=javascript>if (!confirm('" + message + "')) {window.location.replace('" + NOURL + "')} else {window.location.replace('" + YESURL + "')} </script>";
  52. HttpContext.Current.Response.Write(js);
  53. HttpContext.Current.Response.End();
  54. }
  55. /// <summary>
  56. /// 弹出JavaScript小窗口
  57. /// </summary>
  58. public static void Alert(string message)
  59. {
  60. string js = @"<Script language='JavaScript'>alert('" + message + "');</Script>";
  61. HttpContext.Current.Response.Write(js);
  62. HttpContext.Current.Response.End();
  63. }
  64. /// <summary>
  65. /// 弹出JavaScript小窗口并关闭窗口
  66. /// </summary>
  67. public static void AlertAndCloseWindow(string message)
  68. {
  69. string js = @"<Script language='JavaScript'>alert('" + message + "');window.close();</Script>";
  70. HttpContext.Current.Response.Write(js);
  71. HttpContext.Current.Response.End();
  72. }
  73. /// <summary>
  74. /// 弹出JavaScript小窗口,回到历史页面
  75. /// </summary>
  76. /// <param name="message">消息</param>
  77. /// <param name="value">-1/1</param>
  78. public static void GoHistory(string message, int value)
  79. {
  80. string js = @"<Script language='JavaScript'>alert('{0}');history.go({1});</Script>";
  81. HttpContext.Current.Response.Write(string.Format(js, message, value));
  82. HttpContext.Current.Response.End();
  83. }
  84. /// <summary>
  85. /// 关闭当前窗口
  86. /// </summary>
  87. public static void CloseWindow()
  88. {
  89. string js = @"<Script language='JavaScript'>
  90. window.close();
  91. </Script>";
  92. HttpContext.Current.Response.Write(js);
  93. HttpContext.Current.Response.End();
  94. }
  95. /// <summary>
  96. /// 转向Url指定的页面
  97. /// </summary>
  98. /// <param name="url"></param>
  99. public static void JSRedirectUrl(string url)
  100. {
  101. string js = @"<Script language='JavaScript'>
  102. window.location.replace('{0}');
  103. </Script>";
  104. js = string.Format(js, url);
  105. HttpContext.Current.Response.Write(js);
  106. HttpContext.Current.Response.End();
  107. }
  108. /// <summary>
  109. /// 父页转向Url指定的页面
  110. /// </summary>
  111. /// <param name="url"></param>
  112. public static void JSTopRedirectUrl(string url)
  113. {
  114. string js = @"<Script language='JavaScript'>
  115. window.top.location.replace('{0}');
  116. </Script>";
  117. js = string.Format(js, url);
  118. HttpContext.Current.Response.Write(js);
  119. HttpContext.Current.Response.End();
  120. }
  121. /// <summary>
  122. /// 新窗口打开
  123. /// </summary>
  124. /// <param name="url"></param>
  125. public static void JSOpenUrl(string url)
  126. {
  127. string js = @"<Script language='JavaScript'>
  128. window.open('{0}');
  129. </Script>";
  130. js = string.Format(js, url);
  131. HttpContext.Current.Response.Write(js);
  132. HttpContext.Current.Response.End();
  133. }
  134. }
  135. }