1. 标准的方法
<script type=\"text/javascript\">
function openWin(src, width, height, showScroll){
window.showModalDialog (src,\"\",\"location:No;status:No;help:No;dialogWidth:\"+width+\";dialogHeight:\"+height+\";scroll:\"+showScroll+\";\");
}
</script>
例:<span style=\"CURSOR: pointer\" onclick=\"openWin
(\'http://www.phpstudy.net\', \'500px\', \'400px\', \'no\')\">点击</span>
2. 要注意的是,Firefox并不支持该功能,它支持的语法是
window.open
(\'openwin.html\',\'newWin\', \'modal=yes, width=200,height=200,resizable=no, scrollbars=no\' );
3. 如何自动判断浏览器
<input type=\"button\" value=\"打开对话框\" onclick=\"showDialog(\'#\')\"/>
<SCRIPT LANGUAGE=\"JavaScript\">
<!--
function showDialog(url)
{
if( document.all ) //IE
{
feature=\"dialogWidth:300px;dialogHeight:200px;status:no;help:no\";
window.showModalDialog(url,null,feature);
}
else
{
//modelessDialog可以将modal换成dialog=yes
feature =\"width=300,height=200,menubar=no,toolbar=no,location=no,\";
feature+=\"scrollbars=no,status=no,modal=yes\";
window.open(url,null,feature);
}
}
//-->
</SCRIPT>
4. 在IE中,模态对话框会隐藏地址栏,而在其他浏览器则不一定
【注意】在谷歌浏览器中,这个模态的效果也会失效。
5. 一般在弹出对话框的时候,我们都希望整个父页面的背景变为一个半透明的颜色,让用户看到后面是不可以访问的
而关闭对话框之后又希望还原
这是怎么做到的呢?
///显示某个订单的详细信息,通过一个模态对话框,而且屏幕会变颜色
function ShowOrderDetails(orderId) {
var url = \"details.aspx?orderID=\" + orderId;
// $(\"body\").css(\"filter\", \"Alpha(Opacity=20)\");
//filter:Alpha(Opacity=50)
$(\"body\").addClass(\"body1\");
ShowDetailsDialog(url, \"600px\", \"400px\", \"yes\");
$(\"body\").removeClass(\"body1\");
}