473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

HOW: Center this popup message on screen.

The page below creates a popup message on the screen. It printed the
popup box 30 pixels from the left:

document.getElementById("dwindow").style.left="30p x"

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=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
return (!window.opera && document.compatMode &&
document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e){
if (ie5&&dragapproved&&event.button==1){
document.getElementById("dwindow").style.left=temp x+event.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy +event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
document.getElementById("dwindow").style.left=temp x+e.clientX-offsetx+"px"
document.getElementById("dwindow").style.top=tempy +e.clientY-offsety+"px"
}
}

function initializedrag(e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
document.getElementById("dwindowcontent").style.di splay="none" //extra
tempx=parseInt(document.getElementById("dwindow"). style.left)
tempy=parseInt(document.getElementById("dwindow"). style.top)

dragapproved=true
document.getElementById("dwindow").onmousemove=dra g_drop
}

function loadwindow(url,width,height){
if (!ie5&&!ns6)
window.open(url,"","width=width,height=height,scro llbars=1")
else{
document.getElementById("dwindow").style.display=' '
document.getElementById("dwindow").style.width=ini tialwidth=width+"px"
document.getElementById("dwindow").style.height=in itialheight=height+"px"
document.getElementById("dwindow").style.left="30p x"
document.getElementById("dwindow").style.top=ns6?
window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
document.getElementById("cframe").src=url
}
}

function maximize(){
if (minrestore==0){
minrestore=1 //maximize window
document.getElementById("maxname").setAttribute("s rc","restore.gif")
document.getElementById("dwindow").style.width=ns6 ?
window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
document.getElementById("dwindow").style.height=ns 6?
window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
}
else{
minrestore=0 //restore window
document.getElementById("maxname").setAttribute("s rc","max.gif")
document.getElementById("dwindow").style.width=ini tialwidth
document.getElementById("dwindow").style.height=in itialheight
}
document.getElementById("dwindow").style.left=ns6?
window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
document.getElementById("dwindow").style.top=ns6?
window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit(){
document.getElementById("dwindow").style.display=" none"
}

function stopdrag(){
dragapproved=false;
document.getElementById("dwindow").onmousemove=nul l;
document.getElementById("dwindowcontent").style.di splay="" //extra
}

</script>
</head>
<body>

<div id="dwindow"
style="position:absolute;cursor:hand;left:0px;top: 0px;display:none"
onMousedown="initializedrag(event)" onMouseup="stopdrag()"
onSelectStart="return false">
<div align="right" style="background-color:gray"><img src="max.gif"
id="maxname" onClick="maximize()"><img src="close.gif"
onClick="closeit()"></div>
<div id="dwindowcontent" style="height:100%">

<table width="100%" cellpadding="5" cellspacing="5"
style="border-collapse: collapse; border: 1px solid #000000"
bordercolor="#111111" 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=new Function('loadwindow("",350,150)')
else
loadwindow("",350,250)
</script>
</body>
</html>
Nov 9 '05 #1
1 2599
Blue® wrote:
The page below creates a popup message on the screen. It printed the
popup box 30 pixels from the left:

document.getElementById("dwindow").style.left="30p x"
All DOM features should be subject to previous tests at runtime.

<http://pointedears.de/scripts/test/whatami>
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 [...]


Does not matter. It is a CSS question and thus belongs into the
respective newsgroup, comp.infosystems.www.authoring.stylesheets.

Come back here if you have problems implementing the CSS solution
through the DOM. Be sure to use Google Groups archives before you
post.

<http://jibbering.com/faq/>
PointedEars
Nov 9 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mica Cooper | last post by:
Hi, I have a series of Select menus on a page. I am trying to allow the user to click on the Select title and have it popup a help window. This works fine with the following code except that all...
2
by: Reply Via Newsgroup | last post by:
Folks, I'm pretty sure it can be done, and I'm doing pretty good with my javascript so I'm pretty sure I just need a quick point in the right direction... If my web page is referenced in the...
3
by: Ali Chambers | last post by:
Hi, I'd like to open a popup window in the middle of the current browser window. The browser window could be any size and height (as resized by the user). The popup should be in the center of x...
23
by: Markus | last post by:
Hi, i have this problem: Sometimes, i can't reproduce, if i click on an small image on the website, the popup _AND_ an other Tab in firefox open. Here are the linkcode: <div...
6
by: Blue® | last post by:
The page below creates a popup message on the screen. It printed the popup box 30 pixels from the left: document.getElementById("dwindow").style.left="30px" How do I modify it so that the...
7
by: bu | last post by:
I have a form with a handful of comments fields. I am trying to code the form in such a way that when the user clicks on the field, a dialog box will open up displaying the full contents of the...
3
by: tshad | last post by:
I have the following: <tr valign="baseline"> <td align="center" width="103" colspan=2 nowrap> <asp:Button ID="ViewPositions" runat="server" Text="View Positions" OnClick="ViewPositions_Click"...
7
by: J-T | last post by:
My website is fine when it is viewed in 1280 by 1024 pixel ,but in smaller resulotions there is a horizontal scrollbar down the page.How can I set it to be viewed the same for all resulotions? ...
4
by: Mori | last post by:
I am using masterPage and I need to populate a textbox that is in a content control with data from popup page that is not part of the master page. This code works if no masterpage is involved. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.