📄 js.cs
字号:
public static void JavaScriptSetCookie(string strName,string strValue)
{
string js=@"<script language=Javascript>
var the_cookie = '"+strName+"="+strValue+@"'
var dateexpire = 'Tuesday, 01-Dec-2020 12:00:00 GMT';
//document.cookie = the_cookie;//写入Cookie<BR>} <BR>
document.cookie = the_cookie + '; expires='+dateexpire;
</script>";
HttpContext.Current.Response.Write(js);
}
/// <summary>
/// 函数名:GotoParentWindow
/// 功能描述:返回父窗口
/// 处理流程:
/// 算法描述:
/// 作 者:
/// 日 期: 2003-04-30 10:00
/// 修 改:
/// 日 期:
/// 版 本:
/// </summary>
/// <param name="parentWindowUrl">父窗口</param>
public static void GotoParentWindow(string parentWindowUrl)
{
string js=@"<Script language='JavaScript'>
this.parent.location.replace('"+parentWindowUrl+"');</Script>";
HttpContext.Current.Response.Write(js);
}
/// <summary>
/// 函数名:ReplaceParentWindow
/// 功能描述:替换父窗口
/// 处理流程:
/// 算法描述:
/// 作 者:
/// 日 期: 2003-04-30 10:00
/// 修 改:
/// 日 期:
/// 版 本:
/// </summary>
/// <param name="parentWindowUrl">父窗口</param>
/// <param name="caption">窗口提示</param>
/// <param name="future">窗口特征参数</param>
public static void ReplaceParentWindow(string parentWindowUrl,string caption,string future)
{
string js="";
if(future!=null&&future.Trim()!="")
{
js=@"<script language=javascript>this.parent.location.replace('"+parentWindowUrl+"','"+caption+"','"+future+"');</script>";
}
else
{
js=@"<script language=javascript>var iWidth = 0 ;var iHeight = 0 ;iWidth=window.screen.availWidth-10;iHeight=window.screen.availHeight-50;
var 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);
}
/// <summary>
/// 函数名:ReplaceOpenerWindow
/// 功能描述:替换当前窗体的打开窗口
/// 处理流程:
/// 算法描述:
/// 作 者:
/// 日 期: 2003-04-30 16:00
/// 修 改:
/// 日 期:
/// 版 本:
/// </summary>
/// <param name="openerWindowUrl">当前窗体的打开窗口</param>
public static void ReplaceOpenerWindow(string openerWindowUrl)
{
string js=@"<Script language='JavaScript'>
window.opener.location.replace('"+openerWindowUrl+"');</Script>";
HttpContext.Current.Response.Write(js);
}
/// <summary>
/// 函数名:ReplaceOpenerParentWindow
/// 功能描述:替换当前窗体的打开窗口的父窗口
/// 处理流程:
/// 算法描述:
/// 作 者:
/// 日 期: 2003-07-03 19:00
/// 修 改:
/// 日 期:
/// 版 本:
/// </summary>
/// <param name="openerWindowUrl">当前窗体的打开窗口的父窗口</param>
public static void ReplaceOpenerParentFrame(string frameName,string frameWindowUrl)
{
string js=@"<Script language='JavaScript'>
window.opener.parent." + frameName + ".location.replace('"+frameWindowUrl+"');</Script>";
HttpContext.Current.Response.Write(js);
}
/// <summary>
/// 函数名:ReplaceOpenerParentWindow
/// 功能描述:替换当前窗体的打开窗口的父窗口
/// 处理流程:
/// 算法描述:
/// 作 者:
/// 日 期:
/// 修 改:
/// 日 期:
/// 版 本:
/// </summary>
/// <param name="openerWindowUrl">当前窗体的打开窗口的父窗口</param>
public static void ReplaceOpenerParentWindow(string openerParentWindowUrl)
{
string js=@"<Script language='JavaScript'>
window.opener.parent.location.replace('"+openerParentWindowUrl+"');</Script>";
HttpContext.Current.Response.Write(js);
}
/// <summary>
/// 函数名:CloseParentWindow
/// 功能描述:关闭窗口
/// 处理流程:
/// 算法描述:
/// 作 者:
/// 日 期: 2003-04-30 16:00
/// 修 改:
/// 日 期:
/// 版 本:
/// </summary>
public static void CloseParentWindow()
{
string js=@"<Script language='JavaScript'>
window.parent.close();
</Script>";
HttpContext.Current.Response.Write(js);
}
public static void CloseOpenerWindow()
{
string js=@"<Script language='JavaScript'>
window.opener.close();
</Script>";
HttpContext.Current.Response.Write(js);
}
/// <summary>
/// 函数名:ShowModalDialogJavascript
/// 功能描述:返回打开模式窗口的脚本
/// 处理流程:
/// 算法描述:
/// 作 者:
/// 日 期:
/// 修 改:
/// 日 期:
/// 版 本:
/// </summary>
/// <param name="webFormUrl"></param>
/// <returns></returns>
public static string ShowModalDialogJavascript(string webFormUrl)
{
string js=@"<script language=javascript>
var iWidth = 0 ;
var iHeight = 0 ;
iWidth=window.screen.availWidth-10;
iHeight=window.screen.availHeight-50;
var szFeatures = 'dialogWidth:'+iWidth+';dialogHeight:'+iHeight+';dialogLeft:0px;dialogTop:0px;center:yes;help=no;resizable:on;status:on;scroll=yes';
showModalDialog('"+webFormUrl+"','',szFeatures);</script>";
return js;
}
public static string ShowModalDialogJavascript(string webFormUrl,string features)
{
string js=@"<script language=javascript>
showModalDialog('"+webFormUrl+"','','"+features+"');</script>";
return js;
}
/// <summary>
/// 函数名:ShowModalDialogWindow
/// 功能描述:打开模式窗口
/// 处理流程:
/// 算法描述:
/// 作 者:
/// 日 期:
/// 修 改:
/// 日 期:
/// 版 本:
/// </summary>
/// <param name="webFormUrl"></param>
/// <returns></returns>
public static void ShowModalDialogWindow(string webFormUrl)
{
string js=ShowModalDialogJavascript(webFormUrl);
HttpContext.Current.Response.Write(js);
}
public static void ShowModalDialogWindow(string webFormUrl,string features)
{
string js=ShowModalDialogJavascript(webFormUrl,features);
HttpContext.Current.Response.Write(js);
}
public static void ShowModalDialogWindow(string webFormUrl,int width,int height,int top,int left)
{
string features = "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";
ShowModalDialogWindow(webFormUrl,features);
}
public static void SetHtmlElementValue(string formName,string elementName,string elementValue)
{
string js=@"<Script language='JavaScript'>if(document."+formName+"." + elementName +"!=null){document."+formName+"." + elementName +".value ="+ elementValue +";}</Script>";
HttpContext.Current.Response.Write(js);
}
/// <summary>
/// 判断Session中某键值是否存在,如果不存在,输出提示信息
/// 并且转向相应页面
/// </summary>
/// <param name="SessionName">Session中键名称</param>
/// <param name="Message">提示信息</param>
/// <param name="RedirectUrl">要转向的页面</param>
public static void CheckSession(string SessionName, string Message, string RedirectUrl)
{
Session = HttpContext.Current.Session;
Response = HttpContext.Current.Response;
if (Session[SessionName] == null)
{
WriteMessage(Message, false, false);
string js = "top.document.location='" + RedirectUrl + "';";
WriteJavaScript(js); ;
}
}
/// <summary>
/// 用Javascript的Window.alert()方法输出提示信息
/// </summary>
/// <param name="strMsg">要输出的信息</param>
/// <param name="Back">输出信息后是否要history.back()</param>
/// <param name="End">输出信息后是否要Response.end()</param>
public static void WriteMessage(string strMsg, bool Back, bool End)
{
Response = HttpContext.Current.Response;
//将单引号替换,防止javascript出错
strMsg = strMsg.Replace("'", "“");
//将回车换行符去掉,防止javascript出错
strMsg = strMsg.Replace("\r\n", "");
Response.Write("<script language=javascript>alert('" + strMsg + "');</script>");
if (Back)
Response.Write("<script language=javascript>history.back();</script>");
if (End)
Response.End();
}
/// <summary>
/// 以Response.Write()方式输出一条JavaScript语句
/// </summary>
/// <param name="strJavaScript">要输出的JavaScript语句</param>
public static void WriteJavaScript(string strJavaScript)
{
Response = HttpContext.Current.Response;
Response.Write("<script language=javascript>" + strJavaScript + "</script>");
}
public static string MD5(string s)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(s, "MD5");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -