The page below creates a popup message on the screen. It printed the
popup box 30 pixels from the left:
document.getEle mentById("dwind ow").style.left ="30px"
How do I modify it so that the popup box is always centered on the
screen regardless of the monitor resolution of the users?
I do not know JS and I have been testing without success. Anybody can
help? Thanks.
=============== =============== =============== ===========
<html>
<head>
<script>
var dragapproved=fa lse
var minrestore=0
var initialwidth,in itialheight
var ie5=document.al l&&document.get ElementById
var ns6=document.ge tElementById&&! document.all
function iecompattest(){
return (!window.opera && document.compat Mode &&
document.compat Mode!="BackComp at")? document.docume ntElement : document.body
}
function drag_drop(e){
if (ie5&&dragappro ved&&event.butt on==1){
document.getEle mentById("dwind ow").style.left =tempx+event.cl ientX-offsetx+"px"
document.getEle mentById("dwind ow").style.top= tempy+event.cli entY-offsety+"px"
}
else if (ns6&&dragappro ved){
document.getEle mentById("dwind ow").style.left =tempx+e.client X-offsetx+"px"
document.getEle mentById("dwind ow").style.top= tempy+e.clientY-offsety+"px"
}
}
function initializedrag( e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getEle mentById("dwind owcontent").sty le.display="non e" //extra
tempx=parseInt( document.getEle mentById("dwind ow").style.left )
tempy=parseInt( document.getEle mentById("dwind ow").style.to p)
dragapproved=tr ue
document.getEle mentById("dwind ow").onmousemov e=drag_drop
}
function loadwindow(url, width,height){
if (!ie5&&!ns6)
window.open(url ,"","width=widt h,height=height ,scrollbars=1")
else{
document.getEle mentById("dwind ow").style.disp lay=''
document.getEle mentById("dwind ow").style.widt h=initialwidth= width+"px"
document.getEle mentById("dwind ow").style.heig ht=initialheigh t=height+"px"
document.getEle mentById("dwind ow").style.left ="30px"
document.getEle mentById("dwind ow").style.top= ns6?
window.pageYOff set*1+30+"px" : iecompattest(). scrollTop*1+30+ "px"
document.getEle mentById("cfram e").src=url
}
}
function maximize(){
if (minrestore==0) {
minrestore=1 //maximize window
document.getEle mentById("maxna me").setAttribu te("src","resto re.gif")
document.getEle mentById("dwind ow").style.widt h=ns6?
window.innerWid th-20+"px" : iecompattest(). clientWidth+"px "
document.getEle mentById("dwind ow").style.heig ht=ns6?
window.innerHei ght-20+"px" : iecompattest(). clientHeight+"p x"
}
else{
minrestore=0 //restore window
document.getEle mentById("maxna me").setAttribu te("src","max.g if")
document.getEle mentById("dwind ow").style.widt h=initialwidth
document.getEle mentById("dwind ow").style.heig ht=initialheigh t
}
document.getEle mentById("dwind ow").style.left =ns6?
window.pageXOff set+"px" : iecompattest(). scrollLeft+"px"
document.getEle mentById("dwind ow").style.top= ns6?
window.pageYOff set+"px" : iecompattest(). scrollTop+"px"
}
function closeit(){
document.getEle mentById("dwind ow").style.disp lay="none"
}
function stopdrag(){
dragapproved=fa lse;
document.getEle mentById("dwind ow").onmousemov e=null;
document.getEle mentById("dwind owcontent").sty le.display="" //extra
}
</script>
</head>
<body>
<div id="dwindow"
style="position :absolute;curso r:hand;left:0px ;top:0px;displa y:none"
onMousedown="in itializedrag(ev ent)" onMouseup="stop drag()"
onSelectStart=" return false">
<div align="right" style="backgrou nd-color:gray"><im g src="max.gif"
id="maxname" onClick="maximi ze()"><img src="close.gif"
onClick="closei t()"></div>
<div id="dwindowcont ent" style="height:1 00%">
<table width="100%" cellpadding="5" cellspacing="5"
style="border-collapse: collapse; border: 1px solid #000000"
bordercolor="#1 11111" id="AutoNumber1 ">
<tr>
<td>This is the popup message. This is the popup message.</td>
</tr>
</table>
</div>
</div>
<script>
//Use below code to load DHTML Window as page loads
if (ns6) window.onload=n ew Function('loadw indow("",350,15 0)')
else
loadwindow("",3 50,250)
</script>
</body>
</html>
popup box 30 pixels from the left:
document.getEle mentById("dwind ow").style.left ="30px"
How do I modify it so that the popup box is always centered on the
screen regardless of the monitor resolution of the users?
I do not know JS and I have been testing without success. Anybody can
help? Thanks.
=============== =============== =============== ===========
<html>
<head>
<script>
var dragapproved=fa lse
var minrestore=0
var initialwidth,in itialheight
var ie5=document.al l&&document.get ElementById
var ns6=document.ge tElementById&&! document.all
function iecompattest(){
return (!window.opera && document.compat Mode &&
document.compat Mode!="BackComp at")? document.docume ntElement : document.body
}
function drag_drop(e){
if (ie5&&dragappro ved&&event.butt on==1){
document.getEle mentById("dwind ow").style.left =tempx+event.cl ientX-offsetx+"px"
document.getEle mentById("dwind ow").style.top= tempy+event.cli entY-offsety+"px"
}
else if (ns6&&dragappro ved){
document.getEle mentById("dwind ow").style.left =tempx+e.client X-offsetx+"px"
document.getEle mentById("dwind ow").style.top= tempy+e.clientY-offsety+"px"
}
}
function initializedrag( e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getEle mentById("dwind owcontent").sty le.display="non e" //extra
tempx=parseInt( document.getEle mentById("dwind ow").style.left )
tempy=parseInt( document.getEle mentById("dwind ow").style.to p)
dragapproved=tr ue
document.getEle mentById("dwind ow").onmousemov e=drag_drop
}
function loadwindow(url, width,height){
if (!ie5&&!ns6)
window.open(url ,"","width=widt h,height=height ,scrollbars=1")
else{
document.getEle mentById("dwind ow").style.disp lay=''
document.getEle mentById("dwind ow").style.widt h=initialwidth= width+"px"
document.getEle mentById("dwind ow").style.heig ht=initialheigh t=height+"px"
document.getEle mentById("dwind ow").style.left ="30px"
document.getEle mentById("dwind ow").style.top= ns6?
window.pageYOff set*1+30+"px" : iecompattest(). scrollTop*1+30+ "px"
document.getEle mentById("cfram e").src=url
}
}
function maximize(){
if (minrestore==0) {
minrestore=1 //maximize window
document.getEle mentById("maxna me").setAttribu te("src","resto re.gif")
document.getEle mentById("dwind ow").style.widt h=ns6?
window.innerWid th-20+"px" : iecompattest(). clientWidth+"px "
document.getEle mentById("dwind ow").style.heig ht=ns6?
window.innerHei ght-20+"px" : iecompattest(). clientHeight+"p x"
}
else{
minrestore=0 //restore window
document.getEle mentById("maxna me").setAttribu te("src","max.g if")
document.getEle mentById("dwind ow").style.widt h=initialwidth
document.getEle mentById("dwind ow").style.heig ht=initialheigh t
}
document.getEle mentById("dwind ow").style.left =ns6?
window.pageXOff set+"px" : iecompattest(). scrollLeft+"px"
document.getEle mentById("dwind ow").style.top= ns6?
window.pageYOff set+"px" : iecompattest(). scrollTop+"px"
}
function closeit(){
document.getEle mentById("dwind ow").style.disp lay="none"
}
function stopdrag(){
dragapproved=fa lse;
document.getEle mentById("dwind ow").onmousemov e=null;
document.getEle mentById("dwind owcontent").sty le.display="" //extra
}
</script>
</head>
<body>
<div id="dwindow"
style="position :absolute;curso r:hand;left:0px ;top:0px;displa y:none"
onMousedown="in itializedrag(ev ent)" onMouseup="stop drag()"
onSelectStart=" return false">
<div align="right" style="backgrou nd-color:gray"><im g src="max.gif"
id="maxname" onClick="maximi ze()"><img src="close.gif"
onClick="closei t()"></div>
<div id="dwindowcont ent" style="height:1 00%">
<table width="100%" cellpadding="5" cellspacing="5"
style="border-collapse: collapse; border: 1px solid #000000"
bordercolor="#1 11111" id="AutoNumber1 ">
<tr>
<td>This is the popup message. This is the popup message.</td>
</tr>
</table>
</div>
</div>
<script>
//Use below code to load DHTML Window as page loads
if (ns6) window.onload=n ew Function('loadw indow("",350,15 0)')
else
loadwindow("",3 50,250)
</script>
</body>
</html>
Comment