常用的Js类
ClientScript.RegisterStartupScript(this.GetType(), "no", JS.Alert(strErrMsg));
Code
Code
using System;
using System.Collections.Generic;
using System.Text;
namespace RM.Common
{
public class JS
{
private static string strJsHead = "<script language=\"javascript\">";
private static string strJsFoot = "</script>";
#region Alert:弹出消息框.
/// <summary>
/// 弹出消息框.
/// </summary>
/// <param name="msg">消息内容.</param>
/// <returns>包含script标签的字符.</returns>
public static string Alert(string msg)
{
string strJs = strJsHead + "alert(\"" + msg + "\");" + strJsFoot;
return strJs;
}
/// <summary>
/// 弹出消息框.
/// </summary>
/// <param name="msg">消息内容.</param>
/// <param name="url">要跳转的Url.</param>
/// <returns>包含script标签的字符.</returns>
public static string Alert(string msg, string url)
{
string strJs = strJsHead + "alert(\"" + msg + "\");document.location=\"" + url + "\";" + strJsFoot;
return strJs;
}
#endregion
#region Back:浏览器历史记录后退.
/// <summary>
/// 浏览器历史记录后退.
/// </summary>
/// <returns>包含script标签的字符.</returns>
public static string Back()
{
string strJs = strJsHead + "history.back(1);" + strJsFoot;
return strJs;
}
/// <summary>
/// 后退.
/// </summary>
/// <param name="step">后退的步数.</param>
/// <returns>包含script标签的字符.</returns>
public static string Back(int step)
{
string strJs = strJsHead + "history.back(" + step + ");" + strJsFoot;
return strJs;
}
#endregion
#region Go:浏览器历史记录前进或后退.
/// <summary>
/// 浏览器历史记录前进或后退.
/// </summary>
/// <param name="step"></param>
/// <returns></returns>
public static string Go(int step)
{
string strJs = strJsHead + "history.go(" + step + ")" + strJsFoot;
return strJs;
}
#endregion
#region Redirect:跳转到指定的URL.
/// <summary>
/// 跳转到指定的URL.
/// </summary>
/// <param name="sUrl">要跳转到的URL地址.</param>
/// <returns>包含script标签的字符.</returns>
public static string Redirect(string sUrl)
{
string strJs = "document.location=\"" + sUrl + "\";";
strJs = strJsHead + strJs + strJsFoot;
return strJs;
}
#endregion
#region Replace:改变当前页面的URL.
/// <summary>
/// 改变当前页面的URL.
/// </summary>
/// <param name="sUrl">改变后的URL地址.</param>
/// <returns>包含script标签的字符.</returns>
public static string Replace(string sUrl)
{
string strJs = "document.location.replace(\"" + sUrl + "\");";
strJs = strJsHead + strJs + strJsFoot;
return strJs;
}
#endregion
#region CloseWindow:关闭当前浏览器窗口.
/// <summary>
/// 关闭当前浏览器窗口.
/// </summary>
/// <returns>包含script标签的字符.</returns>
public static string CloseWindow()
{
string strJs = strJsHead + "window.close();" + strJsFoot;
return strJs;
}
#endregion
#region RegJs:为自定义的JS加上script标签.
/// <summary>
/// 为自定义的JS加上script标签.
/// </summary>
/// <param name="strJs">自定义的JS.</param>
/// <returns>包含script标签的字符.</returns>
public static string RegJs(string strJs)
{
string qdkRe = strJsHead + strJs + strJsFoot;
return qdkRe;
}
#endregion
#region Reload:重新载入当前页面.
/// <summary>
/// 重新载入当前页面.
/// </summary>
/// <returns>包含script标签的字符.</returns>
public static string Reload()
{
string strJs = "document.location=self.location;";
strJs = strJsHead + strJs + strJsFoot;
return strJs;
}
#endregion
}
}
Code
using System;
using System.Collections.Generic;
using System.Text;
namespace RM.Common
{
public class JS
{
private static string strJsHead = "<script language=\"javascript\">";
private static string strJsFoot = "</script>";
#region Alert:弹出消息框.
/// <summary>
/// 弹出消息框.
/// </summary>
/// <param name="msg">消息内容.</param>
/// <returns>包含script标签的字符.</returns>
public static string Alert(string msg)
{
string strJs = strJsHead + "alert(\"" + msg + "\");" + strJsFoot;
return strJs;
}
/// <summary>
/// 弹出消息框.
/// </summary>
/// <param name="msg">消息内容.</param>
/// <param name="url">要跳转的Url.</param>
/// <returns>包含script标签的字符.</returns>
public static string Alert(string msg, string url)
{
string strJs = strJsHead + "alert(\"" + msg + "\");document.location=\"" + url + "\";" + strJsFoot;
return strJs;
}
#endregion
#region Back:浏览器历史记录后退.
/// <summary>
/// 浏览器历史记录后退.
/// </summary>
/// <returns>包含script标签的字符.</returns>
public static string Back()
{
string strJs = strJsHead + "history.back(1);" + strJsFoot;
return strJs;
}
/// <summary>
/// 后退.
/// </summary>
/// <param name="step">后退的步数.</param>
/// <returns>包含script标签的字符.</returns>
public static string Back(int step)
{
string strJs = strJsHead + "history.back(" + step + ");" + strJsFoot;
return strJs;
}
#endregion
#region Go:浏览器历史记录前进或后退.
/// <summary>
/// 浏览器历史记录前进或后退.
/// </summary>
/// <param name="step"></param>
/// <returns></returns>
public static string Go(int step)
{
string strJs = strJsHead + "history.go(" + step + ")" + strJsFoot;
return strJs;
}
#endregion
#region Redirect:跳转到指定的URL.
/// <summary>
/// 跳转到指定的URL.
/// </summary>
/// <param name="sUrl">要跳转到的URL地址.</param>
/// <returns>包含script标签的字符.</returns>
public static string Redirect(string sUrl)
{
string strJs = "document.location=\"" + sUrl + "\";";
strJs = strJsHead + strJs + strJsFoot;
return strJs;
}
#endregion
#region Replace:改变当前页面的URL.
/// <summary>
/// 改变当前页面的URL.
/// </summary>
/// <param name="sUrl">改变后的URL地址.</param>
/// <returns>包含script标签的字符.</returns>
public static string Replace(string sUrl)
{
string strJs = "document.location.replace(\"" + sUrl + "\");";
strJs = strJsHead + strJs + strJsFoot;
return strJs;
}
#endregion
#region CloseWindow:关闭当前浏览器窗口.
/// <summary>
/// 关闭当前浏览器窗口.
/// </summary>
/// <returns>包含script标签的字符.</returns>
public static string CloseWindow()
{
string strJs = strJsHead + "window.close();" + strJsFoot;
return strJs;
}
#endregion
#region RegJs:为自定义的JS加上script标签.
/// <summary>
/// 为自定义的JS加上script标签.
/// </summary>
/// <param name="strJs">自定义的JS.</param>
/// <returns>包含script标签的字符.</returns>
public static string RegJs(string strJs)
{
string qdkRe = strJsHead + strJs + strJsFoot;
return qdkRe;
}
#endregion
#region Reload:重新载入当前页面.
/// <summary>
/// 重新载入当前页面.
/// </summary>
/// <returns>包含script标签的字符.</returns>
public static string Reload()
{
string strJs = "document.location=self.location;";
strJs = strJsHead + strJs + strJsFoot;
return strJs;
}
#endregion
}
}