|
-
September 21st, 2007, 06:19 AM
#1
To Get the Scroll Height
Hi,
In aspx page
i wrote one function in javasript to show the scrolling height
function scrollingDetector(){
if (navigator.appName == "Microsoft Internet Explorer"){
alert("You've scrolled to " + document.body.scrollTop + " pixels.");
}else{alert ("You've scrolled to " + window.pageYOffset + " pixels.");}
}
and calling this function in <body onscroll= scrollingDetector()
this one is working fine if am not including this below line in the top of <html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
but if i include this line onscroll property of body is not working.
Anybody please help me why it is happening..
waiting for your valuable response
Veeres
-
September 21st, 2007, 06:30 AM
#2
Re: To Get the Scroll Height
Relying on the exact browser like that is bad because you will never get good cross-browser compatability. Here's a script taken from www.quirksmode.org, a great resource on cross-browser compatible JavaScript:
Code:
var x,y;
if (self.pageYOffset) // all except Explorer
{
x = self.pageXOffset;
y = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
x = document.documentElement.scrollLeft;
y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
x = document.body.scrollLeft;
y = document.body.scrollTop;
}
-
September 21st, 2007, 06:47 AM
#3
Re: To Get the Scroll Height
EDIT: Misunderstood the question.
Last edited by PeejAvery; September 21st, 2007 at 11:27 AM.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 21st, 2007, 11:11 AM
#4
Re: To Get the Scroll Height
The code I posted should work in all browsers. Yours doesn't retrieve the values he wanted (he wanted the position of the scroll, not the dimensions of the page.)
The problem he was experiencing was that once he adds the document type, IE goes into strict mode at which point you have to use document.documentElement instead of document.body.
Also, I'm pretty sure that code you posted comes from Quirksmode as well...
Last edited by andreasblixt; September 21st, 2007 at 11:14 AM.
-
September 21st, 2007, 11:26 AM
#5
Re: To Get the Scroll Height
 Originally Posted by andreasblixt
Also, I'm pretty sure that code you posted comes from Quirksmode as well... 
Really? Where? I wrote it a while back when working with an overlay script.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|