Digital Point Forums
San Diego Models

Go Back   Digital Point Forums > Design & Development > Programming > JavaScript
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Mar 23rd 2005, 4:05 pm
rickbkis's Avatar
rickbkis rickbkis is offline
Grunt
 
Join Date: Feb 2005
Location: Anywhere I can park my RV
Posts: 45
rickbkis is on a distinguished road
document.body.scrollTop in IE

I've been using html without the DOCTYPE spec. That worked fine, but I couldn't position a table correctly in css in IE.

From another discussion on the forum, it was recommended to use the following DOCTYPE specification, and tables would position correctly:

Quote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
So, I did that. It worked great for positioning the table.

However, with this DOCTYPE, 'document.body.scrollTop' in IE reports zero, no matter where the body is scrolled.

Yeesh.

I can get around it because I need to position the table in one page (and can specify the DOCTYPE), and I rely on the scrollTop value on another page (and can leave the DOCTYPE off that page).

Not an optimal or elegant solution & besides, I'm going to need the scrollTop value in both pages, later on.

Sooo - Questions:
  1. Is there a better construct/value to use to get the equivalent of 'document.body.scrollTop'
  2. Is there another DOCTYPE that does both correctly?

Any thoughts appreciated.

rickb
Reply With Quote
  #2  
Old Mar 23rd 2005, 4:21 pm
nullbit nullbit is offline
Hand of A'dal
 
Join Date: Feb 2005
Posts: 489
nullbit is on a distinguished road
Post the JS, I'll try help.
__________________
SEO Tool - The killer search engine optimization tool. No. Really.
The Search Engine Experiment - Discover if Google really giving you the most relevant results
- No recip required.
Reply With Quote
  #3  
Old Mar 24th 2005, 2:19 pm
rickbkis's Avatar
rickbkis rickbkis is offline
Grunt
 
Join Date: Feb 2005
Location: Anywhere I can park my RV
Posts: 45
rickbkis is on a distinguished road
Here it is:

<script language="javascript">
function LoadIFrame(jpgfile)
{
var iframe = document.getElementById("bigframe");
iframe.src = "/scribi/lib/IFrameContents.php?fn=" + jpgfile;
iframe.style.left=10;
iframe.style.top = document.body.scrollTop + 10;
iframe.style.display = "block";
}


If I use the transitional 4.01 doctype, document.body.scrollTop always returns zero (in Win IE 6), no matter the scrolling of the page (works fine in FF, Opera.)

Actually, I got both situtations to work reasonably well by reverting to the 3.2 doctype. So, I'm moiving on.

rickb
Reply With Quote
  #4  
Old Apr 11th 2005, 2:28 am
prosiak prosiak is offline
Peon
 
Join Date: Apr 2005
Posts: 1
prosiak is on a distinguished road
I have the same problem Can't using scrollTop when loose.dtd existed.

Mr. Prosiak
Reply With Quote
  #5  
Old Apr 11th 2005, 7:06 am
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
It seems that scrollTop only works if the overflow property is set:

<div style="height: 100px; width: 100px; overflow: scroll;" onclick="alert(this.scrollTop)">
0123456789 0123456789 0123456789 0123456789 0123456789 0123456789
</div>

J.D.
Reply With Quote
  #6  
Old Jun 13th 2005, 9:24 am
RandyTayler RandyTayler is offline
Peon
 
Join Date: Jun 2005
Posts: 1
RandyTayler is on a distinguished road
THANK YOU ALL!

I never would have learned why document.body.scrollTop wasn't working right -- I changed it to a 3.2 doctype and all is well.

The wonders of search engines.
Reply With Quote
  #7  
Old Oct 1st 2005, 2:38 am
geckex geckex is offline
Peon
 
Join Date: Oct 2005
Posts: 1
geckex is on a distinguished road
documentElement sorts it!

IE6 and DTD 4.01 requires you to use document.documentElement in stead of document.body, so u will need somthing like the below:

if (document.documentElement && !document.documentElement.scrollTop)
// IE6 +4.01 but no scrolling going on
else if (document.documentElement && document.documentElement.scrollTop)
// IE6 +4.01 and user has scrolled
else if (document.body && document.body.scrollTop)
// IE5 or DTD 3.2
Reply With Quote
  #8  
Old Oct 1st 2005, 2:49 am
AzAkers's Avatar
AzAkers AzAkers is offline
Twilight Vanquisher
 
Join Date: Mar 2005
Location: Phoenix, AZ
Posts: 988
AzAkers is a jewel in the roughAzAkers is a jewel in the roughAzAkers is a jewel in the rough
isn't it just mind blowing what varied treasures await you at Digital Point!!??
__________________
SEO & Web Design Blog | << Advertise for cheap
Reply With Quote
  #9  
Old Mar 29th 2006, 3:53 pm
sebastianrs's Avatar
sebastianrs sebastianrs is offline
Twilight Vanquisher
 
Join Date: Dec 2005
Location: Germany
Posts: 634
sebastianrs will become famous soon enoughsebastianrs will become famous soon enough
Quote:
isn't it just mind blowing what varied treasures await you at Digital Point!!??
Umm... YES! This one just saved me a few hours for sure
__________________
SRS Solutions - Internet Marketing
Involved? Join the social group Internet Marketing Society now.
Reply With Quote
  #10  
Old Jun 18th 2006, 7:53 pm
dethlon dethlon is offline
Peon
 
Join Date: Jun 2006
Posts: 2
dethlon is on a distinguished road
How to prevent layer scroll up when page is refreshing..

hi..guys..
i have a problem here...

the problem is like this....
i have managed to create a chat application using PHP with the auto refresh...
for the chatting screen, i have used layer to contain all the user chatting messages..as u know..when user keep on typing and sending messages..the layer will eventually and automatically create a vertical scroll...
To retrieve the data from the database...i need to keep the chatting screen(layer page) to be frefreshed in every several seconds...
the problem is..when it is refreshing....the scroll bar in the layer will also be refreshed and the screen will scroll up back to the top of the messages...

so, i wanna ask who knows how to make the scrollbar not to back to top...but stay at the bottom (when page is refreshing)..so that the user can see the latest message they typed...

any javascript methods or other functions can help this?

thanks...
----------------------------------------------------------------------

i have heard some reccomendation to use the document.objectelement.scrollTop method n i try to use it...but i wont works...
this is the sample scenario...

(let's say i want to make the distance become 10000 from the top (scenario 2)

scenario 1:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script language="JavaScript" type="text/JavaScript">
<!--

function scrollUp()
{
document.Layer1.scrollTop = Layer1.scrollHeight;
}


//-->
</script>

<title>Untitled Document</title>
<META HTTP-EQUIV="refresh" content="2;URL=http://localhost/project/ww.php">
</head>
<body onload = "scrollUp()">

<div id="Layer1" style="position:absolute; left:-1px; top:1px; width:600px; height:100px; z-index:1; overflow: scroll; visibility: visible; background-color: #CCFFFF; layer-background-color: #CCFFFF; border: 1px">
1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>
</div>

</body>
</html>



scenario 2 :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<script language="JavaScript" type="text/JavaScript">
<!--

function scrollUp()
{
document.Layer1.scrollTop = 10000;
}


//-->
</script>

<title>Untitled Document</title>
<META HTTP-EQUIV="refresh" content="2;URL=http://localhost/project/ww.php">
</head>
<body onload = "scrollUp()">
<div id="Layer1" style="position:absolute; left:-1px; top:1px; width:600px; height:100px; z-index:1; overflow: scroll; visibility: visible; background-color: #CCFFFF; layer-background-color: #CCFFFF; border: 1px">

1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>

</div>
</body>
</html>

anyone can tell me how to properly use taht method? pls ....
thanks....
Reply With Quote
  #11  
Old Jun 29th 2007, 4:25 am
niklasringdahl niklasringdahl is offline
Peon
 
Join Date: Jun 2007
Posts: 1
niklasringdahl is on a distinguished road
Smile Thanks!

Quote:
Originally Posted by geckex View Post
IE6 and DTD 4.01 requires you to use document.documentElement in stead of document.body, so u will need somthing like the below:

if (document.documentElement && !document.documentElement.scrollTop)
// IE6 +4.01 but no scrolling going on
else if (document.documentElement && document.documentElement.scrollTop)
// IE6 +4.01 and user has scrolled
else if (document.body && document.body.scrollTop)
// IE5 or DTD 3.2
Just wanted to thank you, you saved my day! I struggled with non working js code to get the mouse position, but now it works like a charm!

- Niklas
Reply With Quote
  #12  
Old Aug 22nd 2007, 6:53 am
Blinky82's Avatar
Blinky82 Blinky82 is offline
of the Nightfall
Recent Blog: To SEO or To PPC?
 
Join Date: May 2007
Posts: 1,310
Blinky82 will become famous soon enough
Thanks a lot for this shared info. Find it really interesting.
__________________
Webmaster Forum | Affiliate Marketing | |
Reply With Quote
  #13  
Old Mar 23rd 2008, 8:16 am
akrap akrap is offline
Peon
 
Join Date: Feb 2008
Posts: 16
akrap is on a distinguished road
i know thats very old a topic, but it's usefull. so thaks for this info.
Reply With Quote
  #14  
Old Apr 4th 2008, 4:47 pm
kmofo's Avatar
kmofo kmofo is offline
Hand of A'dal
 
Join Date: Mar 2008
Posts: 336
kmofo will become famous soon enough
now i know why doctype is so important. thanks!
Reply With Quote
  #15  
Old Apr 19th 2008, 8:49 pm
baybossplaya baybossplaya is offline
Twilight Vanquisher
 
Join Date: Aug 2007
Posts: 595
baybossplaya is on a distinguished road
Quote:
Originally Posted by akrap View Post
i know thats very old a topic, but it's usefull. so thaks for this info.
you mean thanks for the pr?
__________________
pinay celebrities pinay bold stars
Reply With Quote
  #16  
Old May 26th 2008, 5:44 am
amoona amoona is offline
Grunt
 
Join Date: May 2008
Posts: 56
amoona is an unknown quantity at this point
This is a useful post. I've learned something good
__________________
Money for Surveys
Reply With Quote
  #17  
Old Jun 4th 2008, 3:48 am
gullam18 gullam18 is offline
Peon
 
Join Date: Oct 2004
Location: Bangalore
Posts: 4
gullam18 is on a distinguished road
Can anybody tell... why is this not working in IE but Firefox?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>Pure CSS Scrollable Table with Fixed Header</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="language" content="en-us" />

<style type="text/css">
<!--


/* define height and width of scrollable area. Add 16px to width for scrollbar */
div.tableContainer {
clear: both;
border: 1px solid #963;
height: 285px;
overflow: auto;
width: 756px
}

/* Reset overflow value to hidden for all non-IE browsers. */
html>body div.tableContainer {
overflow: hidden;
width: 756px
}

/* define width of table. IE browsers only */
div.tableContainer table {
float: left;
width: 740px
}

/* define width of table. Add 16px to width for scrollbar. */
/* All other non-IE browsers. */
html>body div.tableContainer table {
width: 756px
}

/* set table header to a fixed position. WinIE 6.x only */
/* In WinIE 6.x, any element with a position property set to relative and is a child of */
/* an element that has an overflow property set, the relative value translates into fixed. */
/* Ex: parent element DIV with a class of tableContainer has an overflow property set to auto */
thead.fixedHeader tr {
position: relative
}

/* set THEAD element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
html>body thead.fixedHeader tr {
display: block
}

/* make the TH elements pretty */
thead.fixedHeader th {
background: #C96;
border-left: 1px solid #EB8;
border-right: 1px solid #B74;
border-top: 1px solid #EB8;
font-weight: normal;
padding: 4px 3px;
text-align: left
}


/* define the table content to be scrollable */
/* set TBODY element to have block level attributes. All other non-IE browsers */
/* this enables overflow to work on TBODY element. All other non-IE, non-Mozilla browsers */
/* induced side effect is that child TDs no longer accept width: auto */
html>body tbody.scrollContent {
display: block;
height: 262px;
overflow: auto;
width: 100%
}

-->
</style>
<script language="javascript">

var speed = 5;
function scroll(theDiv) {
var div1 = document.getElementById(theDiv);
//alert(div1.scrollHeight);
div1.scrollTop = div1.scrollTop + speed;
//div.scrollTop = div.scrollHeight;
t1=setTimeout("scroll('"+theDiv+"')",1000);
}

function getval(theDiv) {
var div1 = document.getElementById(theDiv);
alert(div1.scrollTop);
}
</script>
</head>
<body onload="scroll('news')">



<div id="tableContainer" class="tableContainer">
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable" class="scrollTable">
<thead class="fixedHeader">
<tr>
<th><a href="#">Header 1</a></th>
<th><a href="#">Header 2</a></th>

<th><a href="#">Header 3</a></th>
</tr>
</thead>
<tbody class="scrollContent" id="news">
<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>

</tr>
<tr>
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr>

<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>

<td>And Repeat 3</td>
</tr>
<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>

<tr>
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr>
<td>Even More Cell Content 1</td>

<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>

</tr>
<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr>

<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr>
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>

<td>Even More Cell Content 3</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>

<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr>
<td>More Cell Content 1</td>

<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr>
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>

</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr>

<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr>
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>

<td>More Cell Content 3</td>
</tr>
<tr>
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>

<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr>
<td>Cell Content 1</td>

<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr>
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>

</tr>
<tr>
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr>

<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>

<td>Cell Content 3</td>
</tr>
<tr>
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>

<tr>
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr>
<td>And Repeat 1</td>

<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>
<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>

</tr>
<tr>
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr>

<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>

<td>And Repeat 3</td>
</tr>
<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>

<tr>
<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr>
<td>Even More Cell Content 1</td>

<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>

</tr>
<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr>

<td>More Cell Content 1</td>
<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr>
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>

<td>Even More Cell Content 3</td>
</tr>
<tr>
<td>And Repeat 1</td>
<td>And Repeat 2</td>
<td>And Repeat 3</td>
</tr>

<tr>
<td>Cell Content 1</td>
<td>Cell Content 2</td>
<td>Cell Content 3</td>
</tr>
<tr>
<td>More Cell Content 1</td>

<td>More Cell Content 2</td>
<td>More Cell Content 3</td>
</tr>
<tr>
<td>Even More Cell Content 1</td>
<td>Even More Cell Content 2</td>
<td>Even More Cell Content 3</td>

</tr>
<tr>
<td>End of Cell Content 1</td>
<td>End of Cell Content 2</td>
<td>End of Cell Content 3</td>
</tr>
</tbody>
</table>

</div>

<input type="button" value="Get ScrollTop" onclick="getval('news');">
<script language="javascript">document.getElementById("news").scrollTop = 1;</script>
</body></html>
Reply With Quote
  #18  
Old Jun 4th 2008, 7:53 pm
crath's Avatar
crath crath is offline
Twilight Vanquisher
 
Join Date: Aug 2007
Location: Philadelphia, PA
Posts: 660
crath will become famous soon enoughcrath will become famous soon enough
please use [ code ] tags guys! its easier for us to help
__________________
[www.ShaneReustle.com] - I volunteer my time to help you, positive reputation is greatly appreciated!
xHtml : CSS : PHP : mySQL : JavaScript : Ajax : XML : Actionscript 3.0 : Flash cs3 : Photoshop cs3
Reply With Quote
  #19  
Old Jun 16th 2008, 11:37 pm
andyoudontstop's Avatar
andyoudontstop andyoudontstop is offline
Grunt
 
Join Date: Jun 2006
Location: Just Over Yonder!
Posts: 42
andyoudontstop is on a distinguished road
@gullam18 :

Internet Explorer does not understand the child selector command

html>body thead.fixedHeader tr {
display: block
}

You can read up more on hacks and tricks needed to get certain functionality to work in Internet Explorer here: http://www.webcredible.co.uk/user-fr...etection.shtml
__________________
Hip Hop - Still Matters!
Reply With Quote
  #20  
Old Jun 28th 2008, 3:31 pm
yantomulia yantomulia is offline
Grunt
 
Join Date: Jun 2008
Posts: 58
yantomulia is on a distinguished road
thanks for sharing this information
__________________
I have Free ebooks website and get style with Indonesian Busana Muslim
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -8. The time now is 9:01 pm.