Web中模态对话框加载后根据加载内容动态改变其大小并使其居中

〈script language="javascript"〉
〈!--

function window.onLoad()
{
window.setTimeout(sizeDialog,1);;
}

function sizeDialog()
{
dialogHeight = (parseInt(layout.offsetHeight) + 30) + "px";;
dialogWidth = (parseInt(layout.offsetWidth) + 10) + "px";;
window.setTimeout(centerDialog,1);;
}

function centerDialog()
{
var TopPosition = (screen.height) ? (screen.height-parseInt(dialogHeight))/2 : 0;;
var LeftPosition = (screen.width) ? (screen.width-parseInt(dialogWidth))/2 : 0;;
dialogTop = TopPosition;;
dialogLeft = LeftPosition;;
}

//--〉
〈/script〉
注:上述代码中的layout为body中的一个table的id,页面的所有控件都包含在此table中,且未设置其width和height属性。
posted @ 2006-03-15 00:07  MaxIE  阅读(317)  评论(0编辑  收藏  举报