常用JavaScript代码提示公共类整理封装,可直接用于项目开发, 作为开发常用代码,还是有一定使用价值的,呵呵 希望对大家有帮助!
Code
using System;
using System.Web;
namespace Jake.PublicJS
{
/// <summary>
/// Summary description for PublicJS
/// </summary>
public class PublicJS
{
public PublicJS()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// 1.静态方法,弹出信息窗体
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="description">信息内容</param>
/// <example>
/// PublicJS.Alert(this,"NiHao!");
/// </example>
public static void Alert(System.Web.UI.Page page, string description)
{
if (description != null)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "alert('" + description + "');";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
else
{
Alert(page, "描述信息为空!");
}
}
/// <summary>
/// 2.静态方法,弹出信息窗体,并刷新页面
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="description">信息内容</param>
/// <example>
/// PublicJS.Alert(this,"NiHao!");
/// </example>
public static void ReLoadMessage(System.Web.UI.Page page, string description, string PageID)
{
if (description != null)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "alert('" + description + "');";
scriptString += "parent." + PageID + ".location.reload()";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
else
{
Alert(page, "描述信息为空!");
}
}
public static void Redirect(string url)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<mce:script language=JScript><!--
\n");
Response.Write("window.location='" + url + "';\n");
Response.Write("
// --></mce:script>\n");
}
/// <summary>
/// 弹出对话框,转向所指页面
/// </summary>
/// <param name="description">提示信息</param>
/// <param name="url">页面</param>
public static void MsgBoxRedrict(string description, string url)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<mce:script language=JScript><!--
\n");
Response.Write("alert('" + description + "');\n");
Response.Write("window.location='" + url + "';\n");
Response.Write("
// --></mce:script>\n");
//Response.Redirect(url);
}
/// <summary>
/// 弹出对话框,确实转向所指页面
/// </summary>
/// <param name="description">提示信息</param>
/// <param name="url">页面</param>
/// <param name="PrintUrl">确定后转向的页面</param>
public static void MsgBoxRedrict(string description, string url, string PrintUrl)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<mce:script language=JScript><!--
\n");
Response.Write("function prints()\n");
Response.Write("{\n if(confirm('" + description + "'))\n");
Response.Write("{window.location='" + PrintUrl + "';}\n");
Response.Write("else\n");
Response.Write("{window.location='" + url + "';}\n}\n");
Response.Write("prints();\n");
Response.Write("
// --></mce:script>\n");
}
/// <summary>
/// 弹出对话框,转向所指页面
/// </summary>
/// <param name="description">提示信息</param>
public static void MsgBoxRedrict(string description)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<mce:script language=JScript><!--
\n");
Response.Write("alert('" + description + "');\n");
Response.Write("history.go(-1);\n");
Response.Write("
// --></mce:script>\n");
}
/// <summary>
///2 静态方法,关闭一个网页的父窗口,例如一个frame关闭其父窗口。
/// </summary>
/// <param name="page">页面对象</param>
/// <example>
/// PublicJS.CloseParent(this);
/// </example>
public static void CloseParent(System.Web.UI.Page page)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.parent.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///2 静态方法,关闭一个网页窗口。
/// </summary>
/// <param name="page">页面对象</param>
/// <example>
/// PublicJS.CloseParent(this);
/// </example>
public static void ClosePage(System.Web.UI.Page page)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///3 静态方法,输出一则消息后关闭一个模态网页窗口并刷新父窗口
/// 前提条件是必须调用此类中的OpenModalDialog方法
/// 在该方法中自动生成刷新方法才能实现父页面刷新。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="page">输出消息</param>
/// <example>
/// PublicJS.CloseModalDialog(this);
/// </example>
public static void CloseModalDialogMessage(System.Web.UI.Page page, string Message)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "alert('" + Message + "');";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///3 静态方法,关闭一个模态网页窗口并刷新父窗口
/// 前提条件是必须调用此类中的OpenModalDialog方法
/// 在该方法中自动生成刷新方法才能实现父页面刷新。
/// </summary>
/// <param name="page">页面对象</param>
/// <example>
/// PublicJS.CloseModalDialog(this);
/// </example>
public static void CloseModalDialog(System.Web.UI.Page page)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
/// 关闭模态网页并传值到父页面
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="strValue">需要传递的值</param>
public static void CloseModalDialog(System.Web.UI.Page page, string strValue)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.returnValue='" + strValue.Trim() + "';";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///4 静态方法,关闭一个网页窗口。
/// </summary>
/// <param name="page">页面对象</param>
/// <example>
/// PublicJS.CloseWindow(this);
/// </example>
public static void CloseWindow(System.Web.UI.Page page)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.opener=null;";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///5 静态方法,执行客户端一小块脚本语言,
///利用page的RegisterClientScriptBlock方法在客户端注册一段脚本,
///参数script无需包括html标记<mce:script type="text/javascript"><!--
、
// --></mce:script>。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="script">javascript脚本</param>
/// <example>
/// PublicJS.ExecuteBlock(this,"alert("Hello");");
/// </example>
public static void ExecuteBlock(System.Web.UI.Page page, string script)
{
if (script != null)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += script;
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript9"))
page.RegisterClientScriptBlock("clientScript9", scriptString);
}
else
{
Alert(page, "JavaScript脚本不能为空!");
}
}
/// <summary>
///6 静态方法,打开一个网页对话框,并生成刷新页面方法。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenModalDialog(page,"weihu.aspx",700,350);
/// </example>
public static void OpenModalDialog(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string scriptString = "<mce:script language='javascript'><!--
";
scriptString += "function Refreshs()";
scriptString += "{";
//scriptString += "window.location.href= window.location.href;";
scriptString += "}";
scriptString += "window.showModalDialog('" + URL + "',window,'dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;center:Yes;help:No;scroll:auto;resizable:No;status:No;');";
scriptString += "window.location.href= window.location.href;";
scriptString += "
// --></mce:script>";
if (!page.IsStartupScriptRegistered("Startup"))
page.RegisterStartupScript("Startup", scriptString);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///7 静态方法,打开一个模式对话框
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Attribute">属性</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenModalDialog(page,"weihu.aspx","scrollbars=yes,status=yes",700,350);
/// </example>
public static void OpenModalDialog(System.Web.UI.Page page, string URL, string Attribute, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
if (Attribute == "")
Attribute = "center:Yes;help:No;scroll:No;resizable:No;status:No;";
string scriptString = "<mce:script language='javascript'><!--
";
//scriptString += "function Refresh()";
//scriptString += "{";
scriptString += "window.showModalDialog('" + URL + "',window,'dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;" + Attribute + "')";
//scriptString += " window.location.href= window.location.href;";
//scriptString += "}";
//scriptString += " Refresh();";
scriptString += "
// --></mce:script>";
if (!page.IsStartupScriptRegistered("Startup"))
page.RegisterStartupScript("Startup", scriptString);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///8 静态方法,打开一个无模式网页对话框。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenDialog(page,"weihu.aspx",700,350);
/// </example>
public static void OpenDialog(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
"
+ "window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=auto,resizable=Yes,width=" + Width + ",height=" + Height + "')"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///9 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <param name="Left">左边距</param>
/// <param name="Top">上边距</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350,10,20);
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL, int Width, int Height, int Left, int Top)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
"
+ "tt = window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top + "'); tt.focus();"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///9 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <param name="Left">左边距</param>
/// <param name="Top">上边距</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350,10,20);
/// </example>
public static void OpenIEWindows(System.Web.UI.Page page, string URL, int Width, int Height, int Left, int Top)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
//string str = "<mce:script language='javascript'><!--
"
// + "window.open('" + URL + "','','location=no,status=no,menubar=yes,scrollbars=yes,resizable=no,width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top + "');"
// + "
// --></mce:script>";
string str = "<mce:script language='javascript'><!--
"
+ "tt = window.open('" + URL + "','','location=no,status=no,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,fullscreen=no'); tt.focus();"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
public static void OpenIEWindows(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
";
str += "a = window.open(\"" + URL + "\", \"\", \"fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=" + Width + ",height=" + Height + "\", true);";
str += "a.focus();";
str += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///10 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx");
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL)
{
if (URL != null)
{
string str = "<mce:script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=screen.availWidth-20,height=screen.availHeight-20,left=10,top=10');"
+ "Cwin.resizeTo(screen.availWidth-20,screen.availHeight-20);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///11 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350);
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
string str = "<mce:script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + ",left=10,top=10');"
+ "Cwin.moveTo((screen.availWidth-" + Width + ")/2,(screen.availHeight-" + Height + ")/2);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///12 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)
///在屏幕的最右边,上下满屏,宽度由参数指定。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <example>
/// PublicJS.OpenIEWindowRight(page,"weihu.aspx",700);
/// </example>
public static void OpenIEWindowRight(System.Web.UI.Page page, string URL, int Width)
{
if (URL != null)
{
if (Width == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
"
+ "newwindow=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + Width + ",height=document.height');"
+ "newwindow.moveTo(screen.width-" + Width + ",0);newwindow.resizeTo(" + Width + ",screen.height);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///13 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等),在屏幕的最右边,上下位置在中间。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenIEWindowRight(page,"weihu.aspx",700,350);
/// </example>
public static void OpenIEWindowRight(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
"
+ "newwindow=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + "');"
+ "newwindow.moveTo(screen.width-" + Width + ",(screen.height-" + Height + ")/2);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
/// 设置控件焦点
/// </summary>
/// <param name="kongjianmc">控件字符串</param>
public static void SheZhiJD(System.Web.UI.Page page, string kongjianmc)
{
string jiaoben = "";
if (kongjianmc != "")
{
jiaoben = "var control;";
jiaoben += "control = document.getElementById('" + kongjianmc + "');";
jiaoben += "if (control!=null) ";
jiaoben += "{document.all['" + kongjianmc + "'].focus();}";
page.RegisterStartupScript("focus", "<mce:script type="text/javascript"><!--
" + jiaoben + "
// --></mce:script>");
}
}
/// <summary>
///14 静态方法,全屏打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx");
/// </example>
public static void OpenIEWindowFill(System.Web.UI.Page page, string URL)
{
if (URL != null)
{
string str = "<mce:script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=(screen.availWidth),height=(screen.availheight),left=10,top=10');"
//+ "alert(screen.availWidth);alert(screen.availheight); Cwin.moveTo(0,0);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
}
}
using System;
using System.Web;
namespace Jake.PublicJS
{
/// <summary>
/// Summary description for PublicJS
/// </summary>
public class PublicJS
{
public PublicJS()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// 1.静态方法,弹出信息窗体
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="description">信息内容</param>
/// <example>
/// PublicJS.Alert(this,"NiHao!");
/// </example>
public static void Alert(System.Web.UI.Page page, string description)
{
if (description != null)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "alert('" + description + "');";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
else
{
Alert(page, "描述信息为空!");
}
}
/// <summary>
/// 2.静态方法,弹出信息窗体,并刷新页面
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="description">信息内容</param>
/// <example>
/// PublicJS.Alert(this,"NiHao!");
/// </example>
public static void ReLoadMessage(System.Web.UI.Page page, string description, string PageID)
{
if (description != null)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "alert('" + description + "');";
scriptString += "parent." + PageID + ".location.reload()";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
else
{
Alert(page, "描述信息为空!");
}
}
public static void Redirect(string url)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<mce:script language=JScript><!--
\n");
Response.Write("window.location='" + url + "';\n");
Response.Write("
// --></mce:script>\n");
}
/// <summary>
/// 弹出对话框,转向所指页面
/// </summary>
/// <param name="description">提示信息</param>
/// <param name="url">页面</param>
public static void MsgBoxRedrict(string description, string url)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<mce:script language=JScript><!--
\n");
Response.Write("alert('" + description + "');\n");
Response.Write("window.location='" + url + "';\n");
Response.Write("
// --></mce:script>\n");
//Response.Redirect(url);
}
/// <summary>
/// 弹出对话框,确实转向所指页面
/// </summary>
/// <param name="description">提示信息</param>
/// <param name="url">页面</param>
/// <param name="PrintUrl">确定后转向的页面</param>
public static void MsgBoxRedrict(string description, string url, string PrintUrl)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<mce:script language=JScript><!--
\n");
Response.Write("function prints()\n");
Response.Write("{\n if(confirm('" + description + "'))\n");
Response.Write("{window.location='" + PrintUrl + "';}\n");
Response.Write("else\n");
Response.Write("{window.location='" + url + "';}\n}\n");
Response.Write("prints();\n");
Response.Write("
// --></mce:script>\n");
}
/// <summary>
/// 弹出对话框,转向所指页面
/// </summary>
/// <param name="description">提示信息</param>
public static void MsgBoxRedrict(string description)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<mce:script language=JScript><!--
\n");
Response.Write("alert('" + description + "');\n");
Response.Write("history.go(-1);\n");
Response.Write("
// --></mce:script>\n");
}
/// <summary>
///2 静态方法,关闭一个网页的父窗口,例如一个frame关闭其父窗口。
/// </summary>
/// <param name="page">页面对象</param>
/// <example>
/// PublicJS.CloseParent(this);
/// </example>
public static void CloseParent(System.Web.UI.Page page)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.parent.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///2 静态方法,关闭一个网页窗口。
/// </summary>
/// <param name="page">页面对象</param>
/// <example>
/// PublicJS.CloseParent(this);
/// </example>
public static void ClosePage(System.Web.UI.Page page)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///3 静态方法,输出一则消息后关闭一个模态网页窗口并刷新父窗口
/// 前提条件是必须调用此类中的OpenModalDialog方法
/// 在该方法中自动生成刷新方法才能实现父页面刷新。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="page">输出消息</param>
/// <example>
/// PublicJS.CloseModalDialog(this);
/// </example>
public static void CloseModalDialogMessage(System.Web.UI.Page page, string Message)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "alert('" + Message + "');";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///3 静态方法,关闭一个模态网页窗口并刷新父窗口
/// 前提条件是必须调用此类中的OpenModalDialog方法
/// 在该方法中自动生成刷新方法才能实现父页面刷新。
/// </summary>
/// <param name="page">页面对象</param>
/// <example>
/// PublicJS.CloseModalDialog(this);
/// </example>
public static void CloseModalDialog(System.Web.UI.Page page)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
/// 关闭模态网页并传值到父页面
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="strValue">需要传递的值</param>
public static void CloseModalDialog(System.Web.UI.Page page, string strValue)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.returnValue='" + strValue.Trim() + "';";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///4 静态方法,关闭一个网页窗口。
/// </summary>
/// <param name="page">页面对象</param>
/// <example>
/// PublicJS.CloseWindow(this);
/// </example>
public static void CloseWindow(System.Web.UI.Page page)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += "window.opener=null;";
scriptString += "window.close();";
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///5 静态方法,执行客户端一小块脚本语言,
///利用page的RegisterClientScriptBlock方法在客户端注册一段脚本,
///参数script无需包括html标记<mce:script type="text/javascript"><!--
、
// --></mce:script>。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="script">javascript脚本</param>
/// <example>
/// PublicJS.ExecuteBlock(this,"alert("Hello");");
/// </example>
public static void ExecuteBlock(System.Web.UI.Page page, string script)
{
if (script != null)
{
string scriptString = "<mce:script language=JavaScript><!--
";
scriptString += script;
scriptString += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript9"))
page.RegisterClientScriptBlock("clientScript9", scriptString);
}
else
{
Alert(page, "JavaScript脚本不能为空!");
}
}
/// <summary>
///6 静态方法,打开一个网页对话框,并生成刷新页面方法。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenModalDialog(page,"weihu.aspx",700,350);
/// </example>
public static void OpenModalDialog(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string scriptString = "<mce:script language='javascript'><!--
";
scriptString += "function Refreshs()";
scriptString += "{";
//scriptString += "window.location.href= window.location.href;";
scriptString += "}";
scriptString += "window.showModalDialog('" + URL + "',window,'dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;center:Yes;help:No;scroll:auto;resizable:No;status:No;');";
scriptString += "window.location.href= window.location.href;";
scriptString += "
// --></mce:script>";
if (!page.IsStartupScriptRegistered("Startup"))
page.RegisterStartupScript("Startup", scriptString);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///7 静态方法,打开一个模式对话框
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Attribute">属性</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenModalDialog(page,"weihu.aspx","scrollbars=yes,status=yes",700,350);
/// </example>
public static void OpenModalDialog(System.Web.UI.Page page, string URL, string Attribute, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
if (Attribute == "")
Attribute = "center:Yes;help:No;scroll:No;resizable:No;status:No;";
string scriptString = "<mce:script language='javascript'><!--
";
//scriptString += "function Refresh()";
//scriptString += "{";
scriptString += "window.showModalDialog('" + URL + "',window,'dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;" + Attribute + "')";
//scriptString += " window.location.href= window.location.href;";
//scriptString += "}";
//scriptString += " Refresh();";
scriptString += "
// --></mce:script>";
if (!page.IsStartupScriptRegistered("Startup"))
page.RegisterStartupScript("Startup", scriptString);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///8 静态方法,打开一个无模式网页对话框。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenDialog(page,"weihu.aspx",700,350);
/// </example>
public static void OpenDialog(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
"
+ "window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=auto,resizable=Yes,width=" + Width + ",height=" + Height + "')"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///9 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <param name="Left">左边距</param>
/// <param name="Top">上边距</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350,10,20);
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL, int Width, int Height, int Left, int Top)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
"
+ "tt = window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top + "'); tt.focus();"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///9 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <param name="Left">左边距</param>
/// <param name="Top">上边距</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350,10,20);
/// </example>
public static void OpenIEWindows(System.Web.UI.Page page, string URL, int Width, int Height, int Left, int Top)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
//string str = "<mce:script language='javascript'><!--
"
// + "window.open('" + URL + "','','location=no,status=no,menubar=yes,scrollbars=yes,resizable=no,width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top + "');"
// + "
// --></mce:script>";
string str = "<mce:script language='javascript'><!--
"
+ "tt = window.open('" + URL + "','','location=no,status=no,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,fullscreen=no'); tt.focus();"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
public static void OpenIEWindows(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
";
str += "a = window.open(\"" + URL + "\", \"\", \"fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=" + Width + ",height=" + Height + "\", true);";
str += "a.focus();";
str += "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///10 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx");
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL)
{
if (URL != null)
{
string str = "<mce:script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=screen.availWidth-20,height=screen.availHeight-20,left=10,top=10');"
+ "Cwin.resizeTo(screen.availWidth-20,screen.availHeight-20);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///11 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350);
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
string str = "<mce:script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + ",left=10,top=10');"
+ "Cwin.moveTo((screen.availWidth-" + Width + ")/2,(screen.availHeight-" + Height + ")/2);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///12 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等)
///在屏幕的最右边,上下满屏,宽度由参数指定。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <example>
/// PublicJS.OpenIEWindowRight(page,"weihu.aspx",700);
/// </example>
public static void OpenIEWindowRight(System.Web.UI.Page page, string URL, int Width)
{
if (URL != null)
{
if (Width == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
"
+ "newwindow=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + Width + ",height=document.height');"
+ "newwindow.moveTo(screen.width-" + Width + ",0);newwindow.resizeTo(" + Width + ",screen.height);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
///13 静态方法,打开一个IE窗口(无标题栏、工具栏、地址栏等),在屏幕的最右边,上下位置在中间。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <param name="Width">宽度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenIEWindowRight(page,"weihu.aspx",700,350);
/// </example>
public static void OpenIEWindowRight(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "页面宽度和高度不能为零!");
return;
}
string str = "<mce:script language='javascript'><!--
"
+ "newwindow=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + "');"
+ "newwindow.moveTo(screen.width-" + Width + ",(screen.height-" + Height + ")/2);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
/// <summary>
/// 设置控件焦点
/// </summary>
/// <param name="kongjianmc">控件字符串</param>
public static void SheZhiJD(System.Web.UI.Page page, string kongjianmc)
{
string jiaoben = "";
if (kongjianmc != "")
{
jiaoben = "var control;";
jiaoben += "control = document.getElementById('" + kongjianmc + "');";
jiaoben += "if (control!=null) ";
jiaoben += "{document.all['" + kongjianmc + "'].focus();}";
page.RegisterStartupScript("focus", "<mce:script type="text/javascript"><!--
" + jiaoben + "
// --></mce:script>");
}
}
/// <summary>
///14 静态方法,全屏打开一个IE窗口(无标题栏、工具栏、地址栏等)。
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="URL">页面名称</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx");
/// </example>
public static void OpenIEWindowFill(System.Web.UI.Page page, string URL)
{
if (URL != null)
{
string str = "<mce:script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=(screen.availWidth),height=(screen.availheight),left=10,top=10');"
//+ "alert(screen.availWidth);alert(screen.availheight); Cwin.moveTo(0,0);"
+ "
// --></mce:script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "页面地址不能为空!");
}
}
}
}