473,327 Members | 2,069 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,327 software developers and data experts.

center a css popup in the browser using javascript

5
What I'm trying to do is to display a loading screen while an ajax request executes. I have a page that is fairly long with several tables worth of data and the sorting/pagination of each table is handled by ajax requests.

I'd like to have a css div that is displayed in the center of the browser window when a user selects an operation that kicks off an ajax request.

What I have thus far is a div that shows up in the center of the "unscrolled" browser window when needed (by unscrolled I mean that if the user were to first hit the page and activate a link in the visible portion of the page - not one found via scrolling down - the div would appear centered in that visible area). The problem that I'm having is that, if the user scrolls down and selects a link the kicks off a request, the div still appears centered on the "top" portion of the page (the original, "unscrolled" portion). I want the pop up div to be displayed in the center of the "visible" area of the browser. Here's the javascript I have thus far:

Expand|Select|Wrap|Line Numbers
  1. function showIndicator(){
  2.     var availHeight;
  3.     var availWidth;
  4.  
  5.     if(typeof(window.innerWidth) == 'number'){
  6.         availHeight = window.innerHeight;
  7.         availWidth = window.innerWidth;
  8.     }else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
  9.         availHeight = document.documentElement.clientHeight;
  10.         availWidth = document.documentElement.clientWidth;
  11.     }else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
  12.         availHeight = document.body.clientHeight;
  13.         availWidth = document.body.clientWidth;
  14.     }
  15.  
  16.     var indicatorWidth = 50;
  17.     var indicatorHeight = 50;
  18.     var left = (availWidth/2) - (indicatorWidth/2);
  19.     var top = (availHeight/2) - (indicatorHeight/2);
  20.     var indicator = document.getElementById('indicator');
  21.     indicator.style.border="1px solid gray";
  22.     indicator.style.background="white";
  23.     indicator.style.position="absolute";
  24.     indicator.style.zIndex="999";
  25.     indicator.style.top=top+"px";
  26.     indicator.style.left=left+"px";
  27.     indicator.style.display="block";
  28. }
  29.  
I hope I was able to convey my intent and my problem - I'm quite new to javascript/dhtml/ajax so I'm mainly hacking away in the dark here.
-I've only tested this in firefox 2 and ie 6 thus far.
Thanks very much!
Apr 2 '07 #1
4 17755
cmo
5
well, ended up figuring this one out after some more hacking,
added the following:
Expand|Select|Wrap|Line Numbers
  1. var yOffset
  2. if (self.pageYOffset){// all except Explorer
  3.     yOffset = self.pageYOffset;
  4. }
  5. else if (document.documentElement && document.documentElement.scrollTop)// Explorer 6 Strict{
  6.     yOffset = document.documentElement.scrollTop;
  7. }
  8. else if (document.body){ // all other Explorers
  9.     y = document.body.scrollTop;
  10. }
  11. ...
  12. var top = ((availHeight/2)+yOffset) - (indicatorHeight/2);
  13. ...
  14.  
and that seems to work just fine.
Apr 2 '07 #2
well, ended up figuring this one out after some more hacking,
added the following:
Expand|Select|Wrap|Line Numbers
  1. var yOffset
  2. if (self.pageYOffset){// all except Explorer
  3.     yOffset = self.pageYOffset;
  4. }
  5. else if (document.documentElement && document.documentElement.scrollTop)// Explorer 6 Strict{
  6.     yOffset = document.documentElement.scrollTop;
  7. }
  8. else if (document.body){ // all other Explorers
  9.     y = document.body.scrollTop;
  10. }
  11. ...
  12. var top = ((availHeight/2)+yOffset) - (indicatorHeight/2);
  13. ...
  14.  
and that seems to work just fine.
I was doing more or less that some days ago
The code i used was something like

Expand|Select|Wrap|Line Numbers
  1. var x = self.pageYOffset ? self.pageXOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollLeft : document.body ? document.body.scrollLeft : null;
  2.  
  3. var y = self.pageYOffset ? self.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body ? document.body.scrollTop : null;
  4.  
Apr 3 '07 #3
Hai im looking for a css inner popup that need to be place along to the window adjustments,

for example : when we right click the mouse on screen where ever the mouse pointer is there option will display accourding to that.

look at this code and position the displaying popup according to the button click

[HTML]<html>
<head>
<title>Inner Popup using CSS</title>
<style type="text/css">
.popup
{
position:absolute; left:0; top:0; width:400px;
border-style:solid;
border-width:1px;
border-color:blue;
background-color:yellow;
padding:5px;
color:red;
font-family:Arial;
font-weight:bold;
font-size:10pt;
z-index:2;
visibility:hidden;
}
</style>
<script language="JavaScript">
function ShowPop(id)
{
document.getElementById(id).style.visibility = "visible";
}
function HidePop(id)
{
document.getElementById(id).style.visibility = "hidden";
}
</script>
</head>
<body>
<table width="100%" class="frm" border=1>
<tr colspan=3>Inner POPUp using CSS
</tr>
<tr>
<td>
<span style="position:relative; background-color:#33d;">
<span id="example" class="popup">
<pre>&lt;script language="JavaScript"&gt;
function ShowPop(id)
{
document.getElementById(id).style.visibility = "visible";
}
function HidePop(id)
{
document.getElementById(id).style.visibility = "hidden";
}
&lt;/script&gt;
<input id="butt" type="button" onClick="HidePop('example');" value="Close" /></pre>
</span>
<input id="butt" type="button" onClick="javascript:void(0);ShowPop('example');" value="click"/></span>
</td>
<td>
<span style="position:relative; background-color:#33d;">
<span id="example" class="popup">
<pre>&lt;script language="JavaScript"&gt;
function ShowPop(id)
{
document.getElementById(id).style.visibility = "visible";
}
function HidePop(id)
{
document.getElementById(id).style.visibility = "hidden";
}
&lt;/script&gt;
<input id="butt" type="button" onClick="HidePop('example');" value="Close" /></pre>
</span>
<input id="butt" type="button" onClick="javascript:void(0);ShowPop('example');" value="Click" /></span>
</td><td>
<span style="position:relative; background-color:#33d;">
<span id="example" class="popup">
<pre>&lt;script language="JavaScript"&gt;
function ShowPop(id)
{
document.getElementById(id).style.visibility = "visible";
}
function HidePop(id)
{
document.getElementById(id).style.visibility = "hidden";
}
&lt;/script&gt;
<input id="butt" type="button" onClick="HidePop('example');" value="Close" /></pre>
</span>
<input id="butt" type="button" onClick="javascript:void(0);ShowPop('example');" value="Click" /></span>
</td>
</tr>
</table>
</body>
</html>[/HTML]

plz find the solution for this, i have to give this to my programmers, who are not able to fix this
Jan 9 '08 #4
acoder
16,027 Expert Mod 8TB
See if you find this article useful.
Jan 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rob V | last post by:
I was wondering whether there was any way of loading an executable or windows shortcut from within a browser using Javascript or something similar. This is for use in an active desktop html file...
1
by: anonieko | last post by:
> Use x = window.Open(...) x.document.write( yourhtml) > How to print from javascript using .print > How to use ContentWindow > > How t use getElementById > How to get HTML of document...
3
by: anthonybrough | last post by:
I have an asp page that has a form to collect user data in a form. when the user clicks submit the input is validated. If any fields are not acceptable the user clicks on a button to go back to...
1
by: webpearl | last post by:
Welcome to all who r helping and sharing their ideas with others.i am a new to this forum.Can any one say an immediate soln on my questions: Qn1: How can i print a hidden data in the hidden data...
1
by: sundarachaitanyam | last post by:
hi, I am just wondering how to create a modal popup using javascript. The popup window shouldnt contain minimize,close and maximize buttons and it should be resizable? I am trying using...
4
by: Nuno | last post by:
Hello, I'm trying to call some web services only using javascript from a html page. I succeeded on doind this in IE with the use of the behavior:url(webservice.htc); (technique founded in the...
4
by: Rakhi | last post by:
hello i want to alter the download settings of mozilla firefox browser using javascript of my application !! wat is happenin in my application is, on calling a method , it make a file ready...
2
by: trivenisri | last post by:
Hi, I am triveni.Can any one know about 'How to open a MS Word document from Javascript in mozilla browser'.I am able to open in IE.Please help me about this issue. Regards, Triveni
1
by: shyamjumberi | last post by:
Hi, I am developing web application.using struts .I want the javascript code for getting the previous URL of the browser. any body help me.
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...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: 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.