using System.Web;
namespace DotNet.Utilities
{
/// <summary>
/// 用戶端腳本輸出
/// </summary>
public class JsHelper
{
/// <summary>
/// 彈出資訊,并跳轉指定頁面。
/// </summary>
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));
HttpContext.Current.Response.End();
}
/// 彈出資訊,并傳回曆史頁面
public static void AlertAndGoHistory(string message, int value)
string js = @"<Script language='JavaScript'>alert('{0}');history.go({1});</Script>";
HttpContext.Current.Response.Write(string.Format(js, message, value));
/// 直接跳轉到指定的頁面
public static void Redirect(string toUrl)
string js = @"<script language=javascript>window.location.replace('{0}')</script>";
HttpContext.Current.Response.Write(string.Format(js, toUrl));
/// 彈出資訊 并指定到父視窗
public static void AlertAndParentUrl(string message, string toURL)
string js = "<script language=javascript>alert('{0}');window.top.location.replace('{1}')</script>";
/// 傳回到父視窗
public static void ParentRedirect(string ToUrl)
string js = "<script language=javascript>window.top.location.replace('{0}')</script>";
HttpContext.Current.Response.Write(string.Format(js, ToUrl));
/// 傳回曆史頁面
public static void BackHistory(int value)
string js = @"<Script language='JavaScript'>history.go({0});</Script>";
HttpContext.Current.Response.Write(string.Format(js, value));
/// 彈出資訊
public static void Alert(string message)
string js = "<script language=javascript>alert('{0}');</script>";
HttpContext.Current.Response.Write(string.Format(js, message));
/// 注冊腳本塊
public static void RegisterScriptBlock(System.Web.UI.Page page, string _ScriptString)
page.ClientScript.RegisterStartupScript(page.GetType(), "scriptblock", "<script type='text/javascript'>" + _ScriptString + "</script>");
}
}