//
/// <summary>
/// javascript弹出窗口封装类
/// </summary>
public static class JSCommon
{
/// <summary>
/// 显示消息提示对话框
/// </summary>
/// <param name="page">当前页面指针,一般为"this"</param>
/// <param name="msg">提示信息</param>
public static void ShowAlert(System.Web.UI.Page page, string msg)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("alert('{0}');", msg);
Builder.Append("</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
/// <summary>
/// 打开大小不可变模式窗口
/// </summary>
/// <param name="page">当前页面指针,一般为"this"</param>
/// <param name="PageUrl">打开的模式窗口显示的网页地址</param>
/// <param name="Width">打开的模式窗口的宽度</param>
/// <param name="Height">打开的模式窗口的高度</param>
public static void OpenFixModalDialog(System.Web.UI.Page page, String PageUrl, int Width, int Height)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("window.showModalDialog('{0}',null,'dialogWidth:{1}px;dialogHeight:{2}px;help:no;unadorned:no;resizable:no;status:no');", PageUrl, Width, Height);
Builder.Append("</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
/// <summary>
/// 打开大小可变模式窗口
/// </summary>
/// <param name="page">当前页面指针,一般为"this"</param>
/// <param name="PageUrl">打开的模式窗口显示的网页地址</param>
/// <param name="Width">打开的模式窗口的宽度</param>
/// <param name="Height">打开的模式窗口的高度</param>
public static void OpenSizeableModalDialog(System.Web.UI.Page page, String PageUrl, int Width, int Height)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("window.showModalDialog('{0}',null,'dialogWidth:{1}px;dialogHeight:{2}px;help:no;unadorned:no;resizable:yes;status:no');", PageUrl, Width, Height);
Builder.Append("</script>");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
/// <summary>
/// 打开悬浮提示窗口
/// </summary>
/// <param name="page">页面指针 一般输入"this"</param>
/// <param name="message">显示的消息</param>
/// <param name="Width">窗口宽度</param>
/// <param name="height">窗口高度</param>
public static void OpenFloatDialog(System.Web.UI.Page page, string message, int Width, int height)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script type='text/javascript' language='javascript' defer>");
// Builder.Append("var msgw,msgh,bordercolor; ");
Builder.AppendLine("function ShowBDDialog(){ ");
Builder.AppendLine("bordercolor='#66ccff';titlecolor='#99CCFF';");
Builder.AppendLine("var sWidth,sHeight; sWidth=document.body.offsetWidth; sHeight=document.body.offsetHeight;");
Builder.AppendLine("var bgObj=document.createElement('div'); ");
Builder.AppendLine(" bgObj.setAttribute('id','bgDiv'); ");
Builder.AppendLine("bgObj.style.position='absolute'; ");
Builder.AppendLine("bgObj.style.top='0'; bgObj.style.background='#dcdcdc';");
Builder.AppendLine("bgObj.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75';");
Builder.AppendLine("bgObj.style.opacity='0.6'; ");
Builder.AppendLine("bgObj.style.left='0';");
Builder.AppendLine("bgObj.style.width=sWidth + 'px'; ");
Builder.AppendLine("bgObj.style.height=sHeight + 'px';");
Builder.AppendLine("document.body.appendChild(bgObj); ");
Builder.AppendLine("var msgObj=document.createElement('div')");
Builder.AppendLine("msgObj.setAttribute('id','msgDiv');");
Builder.AppendLine("msgObj.setAttribute('align','center');");
Builder.AppendLine("msgObj.style.position='absolute';msgObj.style.background='white'; ");
Builder.AppendLine("msgObj.style.font='12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif';");
Builder.AppendLine("msgObj.style.border='1px solid ' + bordercolor;");
Builder.AppendFormat("msgObj.style.width='{0} '+ 'px'; ", Width);
Builder.AppendFormat("msgObj.style.height='{0}' + 'px';", height);
Builder.AppendFormat("msgObj.style.top=(document.documentElement.scrollTop + (sHeight-'{0}')/2) + 'px';", height);
Builder.AppendFormat("msgObj.style.left=(sWidth-'{0}')/2 + 'px';", Width);
Builder.AppendLine("var title=document.createElement('h4');");
Builder.AppendLine("title.setAttribute('id','msgTitle');");
Builder.AppendLine("title.setAttribute('align','right');");
Builder.AppendLine("title.style.margin='0'; ");
Builder.AppendLine("title.style.padding='3px'; title.style.background=bordercolor; ");
Builder.AppendLine("title.style.filter='progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);'; ");
Builder.AppendLine("title.style.opacity='0.75'; ");
Builder.AppendLine("title.style.border='1px solid ' + bordercolor;title.innerHTML='<a style=font-size:small href=#>关闭</a>'; ");
Builder.AppendLine("title.οnclick=function(){ document.body.removeChild(bgObj);document.getElementById('msgDiv').removeChild(title); document.body.removeChild(msgObj);} ");
Builder.AppendLine("document.body.appendChild(msgObj); ");
Builder.AppendLine("document.getElementById('msgDiv').appendChild(title);");
Builder.AppendLine("var txt=document.createElement('p');");
Builder.AppendFormat("txt.style.height='{0}';", height);
Builder.AppendFormat("txt.style.width='{0}';", Width);
Builder.AppendLine(" txt.style.margin='1em 0' ");
Builder.AppendLine("txt.setAttribute('id','msgTxt');");
Builder.AppendFormat("txt.innerHTML='{0}'; ", message);
Builder.AppendLine("document.getElementById('msgDiv').appendChild(txt);return false;}");
Builder.AppendLine(" ShowBDDialog(); </script>");
page.Response.Write(Builder.ToString());
page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javscript'>ShowBDDialog();</" + "script>");
}
/// <summary>
/// 打开悬浮弹出窗口
/// </summary>
/// <param name="page">页面指针 一般输入"this"</param>
/// <param name="url">打开的页面的url</param>
/// <param name="Width">窗口宽度</param>
/// <param name="height">窗口高度</param>
public static void OpenFloatModalWindow(System.Web.UI.Page page, string url, int Width, int height)
{
System.Text.StringBuilder Builder = new System.Text.StringBuilder();
Builder.Append("<script type='text/javascript' language='javascript' defer>");
// Builder.Append("var msgw,msgh,bordercolor; ");
Builder.AppendLine("function ShowBDDialog(){ ");
Builder.AppendLine("bordercolor='#66ccff';titlecolor='#99CCFF';");
Builder.AppendLine("var sWidth,sHeight; sWidth=document.body.offsetWidth; sHeight=document.body.offsetHeight;");
Builder.AppendLine("var bgObj=document.createElement('div'); ");
Builder.AppendLine(" bgObj.setAttribute('id','bgDiv'); ");
Builder.AppendLine("bgObj.style.position='absolute'; ");
Builder.AppendLine("bgObj.style.top='0'; bgObj.style.background='#dcdcdc';");
Builder.AppendLine("bgObj.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75';");
Builder.AppendLine("bgObj.style.opacity='0.6'; ");
Builder.AppendLine("bgObj.style.left='0';");
Builder.AppendLine("bgObj.style.width=sWidth + 'px'; ");
Builder.AppendLine("bgObj.style.height=sHeight + 'px';");
Builder.AppendLine("document.body.appendChild(bgObj); ");
Builder.AppendLine("var msgObj=document.createElement('div')");
Builder.AppendLine("msgObj.setAttribute('id','msgDiv');");
Builder.AppendLine("msgObj.setAttribute('align','center');");
Builder.AppendLine("msgObj.style.position='absolute';msgObj.style.background='white'; ");
Builder.AppendLine("msgObj.style.font='12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif';");
Builder.AppendLine("msgObj.style.border='1px solid ' + bordercolor;");
Builder.AppendFormat("msgObj.style.width='{0} '+ 'px'; ", Width);
Builder.AppendFormat("msgObj.style.height='{0}' + 'px';", height);
Builder.AppendFormat("msgObj.style.top=(document.documentElement.scrollTop + (sHeight-'{0}')/2) + 'px';", height);
Builder.AppendFormat("msgObj.style.left=(sWidth-'{0}')/2 + 'px';", Width);
Builder.AppendLine("var title=document.createElement('h4');");
Builder.AppendLine("title.setAttribute('id','msgTitle');");
Builder.AppendLine("title.setAttribute('align','right');");
Builder.AppendLine("title.style.margin='0'; ");
Builder.AppendLine("title.style.padding='3px'; title.style.background=bordercolor; ");
Builder.AppendLine("title.style.filter='progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);'; ");
Builder.AppendLine("title.style.opacity='0.75'; ");
Builder.AppendLine("title.style.border='1px solid ' + bordercolor;title.innerHTML='<a style=font-size:small href=#>关闭</a>'; ");
Builder.AppendLine("title.οnclick=function(){ document.body.removeChild(bgObj);document.getElementById('msgDiv').removeChild(title); document.body.removeChild(msgObj);} ");
Builder.AppendLine("document.body.appendChild(msgObj); ");
Builder.AppendLine("document.getElementById('msgDiv').appendChild(title);");
Builder.AppendLine("var txt=document.createElement('iframe');");
Builder.AppendFormat("txt.style.height='{0}';", height);
Builder.AppendFormat("txt.style.width='{0}';", Width);
Builder.AppendLine(" txt.style.margin='1em 0' ");
Builder.AppendLine("txt.setAttribute('id','msgTxt');");
Builder.AppendFormat("txt.src='{0}'; ", url);
Builder.AppendLine("document.getElementById('msgDiv').appendChild(txt);return false;}");
Builder.AppendLine(" ShowBDDialog(); </script>");
page.Response.Write(Builder.ToString());
page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javscript'>ShowBDDialog();</" + "script>");
}
}