在onload事件中调用adjustWindowSizeAndPos方法
<script language="javascript">
function adjustWindowSizeAndPos() {
// 设置页面的初始大小,if条件判断是否是模式窗口
if(typeof window.dialogArguments != 'undefined'){
window.dialogHeight = 0+"px";
window.dialogWidth = 0+"px";
}else{
window.resizeTo(0,0);
}
// 定义窗口宽度、窗口高度、屏幕宽度、屏幕高度
var winWidth = document.body.scrollWidth*1.1;
var winHeight = document.body.scrollHeight*1.2;
var availWidth = screen.availWidth;
var availHeight = screen.availHeight;
// 设置最小宽度、高度,最大宽度、高度 (根据屏幕宽度高度的比例计算)
var minWidth = availWidth*0.3;
var minHeight = availHeight*0.3;
var maxWidth = availWidth;
var maxHeight = availHeight*0.85;
// 设置窗口的宽度高度在最小及最大值之间
winWidth = winWidth < minWidth ? minWidth : winWidth;
winHeight = winHeight < minHeight ? minHeight : winHeight;
winWidth = winWidth > maxWidth ? maxWidth : winWidth;
winHeight = winHeight > maxHeight ? maxHeight : winHeight;
// 设置窗口的宽度和高度,设置窗口的位置(if中为模式窗口设置,else中为活动窗口设置)
if(typeof window.dialogArguments != 'undefined'){
window.dialogTop = ((availHeight - winHeight)/2)+"px";
window.dialogLeft = ((availWidth - winWidth)/2)+"px";
window.dialogHeight = winHeight+"px";
window.dialogWidth = winWidth+"px";
}else{
window.moveTo((availWidth - winWidth)/2,(availHeight - winHeight)/2);
window.resizeTo(winWidth,winHeight);
}
}
</script>