调用方法:<input type="button" id="button" value="BUTTON" onclick="CreateDIV(\'测试窗口\',600,300,\'http://www.g.cn\')" />
Javascript 代码:复制
function CreateDIV(winName,divwidth,divheight,url){
var bgIDV = document.getElementById(\'$bgIDV\');
var frame = document.getElementById(\'$frame\');
if(!bgIDV){
bgIDV = document.createElement(\'div\');
document.body.appendChild(bgIDV);
bgIDV.id = \'$bgIDV\';
with(bgIDV.style){
position = \'absolute\';
left = 0;
top = 0;
background = \'#000\';
filter = \'alpha(opacity=30)\';
opacity = 0.3;
display = \'none\';
}
}

if(!frame){
frame = document.createElement(\'div\');
document.body.appendChild(frame);
frame.id = \'$frame\';
with(frame.style){
position = \'absolute\';
display = \'none\';
background = \'#666\';
padding = \'3px\';
}
strFrame = \'<div style=\"border:solid #000 1px;\">\';
strFrame += \'<div style=\"background:#369;padding:3px;height:20px;line-height:20px;font-size:12px\">\';
strFrame += \'<span style=\"color:#fff;float:left;\"><strong>\'+winName+\'</strong></span><span style=\"float:right;color:#fff;font:12px Verdana;cursor:pointer;\" onclick=\"CreateDIV()\"><strong>×</strong></span>\';
strFrame += \'</div>\';
strFrame += \'<iframe marginwidth=\"0\" marginheight=\"0\" width=\"\'+divwidth+\'px\" height=\"\'+divheight+\'px\" frameborder=0 src=\"about:blank\"></iframe>\';
strFrame += \'</div>\';
frame.innerHTML = strFrame;
}
if(bgIDV.style.display == \'none\'){
with(bgIDV.style){
display = \'block\';
width = \'100%\';
height = (document.body.clientHeight+20)+\'px\';
}
with(frame.style){
display = \'block\';
left = (((screen.availWidth - 10) - divwidth)/2)+\'px\';
top = (document.documentElement.scrollTop + (document.documentElement.clientHeight-document.getElementById(\'$frame\').offsetHeight)/2)+\'px\';
}
frame.getElementsByTagName(\'iframe\')[0].contentWindow.location.replace(url);
}
else{
bgIDV.style.display = frame.style.display = \'none\';
frame.getElementsByTagName(\'iframe\')[0].contentWindow.location.replace(\'about:blank\');
}
}