此方法可通用,项目开发中经常要用到:
//w:宽,h:高,url:地址,tag:标记
function showWin(w, h, url, tag) {
var t = (screen.height - h) / 2; //离顶部距离
var l = (screen.width - w) / 2; //离左边距离
window.open(url, tag, "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",location=0");
}
//路径地址,window对象,宽,高
function open_Dialog(url, win, Width, Height) {
var return_Value;
var iTop2 = (window.screen.availHeight - 20 - Height) / 2;
var iLeft2 = (window.screen.availWidth - 10 - Width) / 2;
var height2 = Height;
var mytime = new Date().toLocaleTimeString();
var newUrl = url + '&time=' + mytime;
if (document.all && window.print) {
if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
height2 = Height + 30;
return_Value = window.showModalDialog(newUrl, win, "dialogLeft:" + iLeft2 + "px;dialogTop:" + iTop2 + "px;dialogWidth:" + Width + "px;dialogHeight:" + height2 + "px;center:yes;status:no;scroll:no;help:no;");
}
else {
return_Value = window.showModalDialog(newUrl, win, "dialogLeft:" + iLeft2 + "px;dialogTop:" + iTop2 + "px;dialogWidth:" + Width + "px;dialogHeight:" + Height + "px;center:yes;status:no;scroll:no;help:no;");
}
}
else {
window.open(newUrl, win, "top=" + iTop2 + ",left=" + iLeft2 + ",width=" + Width + "px,height=" + height2 + "px,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no,status=no");
}
}
本文介绍了一种使用JavaScript创建弹窗和对话框的方法,包括如何设置窗口的位置、尺寸及样式等细节,确保跨浏览器的兼容性。
447

被折叠的 条评论
为什么被折叠?



