You can control a scroll bar on a page using window.scrollBy and window.scrollTo... but how can I get the current position of the scrollbar and the maximum position it can be?
I'm working on something that needs the scrollbar position as a percentage and in order to do that I need to know how to do the above.
I've checked out serveral web sites with no luck.
Anyone?
Scroll Bar Information
Moderator: General Moderators
try this oneand do not close the client-window first 
Code: Select all
<html>
<head>
<script langauge="javascript">
var otherWin;
function showPos()
{
if(otherWin!=null)
{
sT = otherWin.document.body.scrollTop;
sH = otherWin.document.body.scrollHeight;
cH = otherWin.document.body.clientHeight;
document.getElementById("scrTop").value = sT;
document.getElementById("scrHeight").value = sH;
document.getElementById("clntHeight").value = cH;
document.getElementById("visFrom").value = sT*100/sH;
document.getElementById("visTo").value = (sT+cH)*100/sH;
}
}
function initWindow()
{
otherWin = window.open("about:blank","win2","width=310,height=50,left=0,top=0,scrollbars=yes,resizable=yes,toolbar=yes,dependent=yes");
otherWin.document.write("<html><head></head><body><h1>1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/></h1></body></html>\n");
window.setInterval("showPos()",100);
}
</script>
</head>
<body onLoad="initWindow();">
<input type="text" id="scrTop" />scrollTop<br/>
<input type="text" id="scrHeight" />scrollHeight<br/>
<input type="text" id="clntHeight" />clientHeight<br/>
visible: <input type="text" id="visFrom" />%to<input type="text" id="visTo" />%
</body>
</html>