Figured it out, just replace document.documentElement.scrollTop
with window.pageYOffset
. So the conditional statement becomes
if (document.body.scrollHeight > (window.pageYOffset + window.innerHeight))
This will take care of the zoom factor.
Question
I am using WebBrowser control to develop a browser app for Windows phone. I am trying to implement auto scroll to the bottom using the following code. It works fine but when the page is zoomed in document.body.scrollHeight
in the the conditional check
if (document.body.scrollHeight > (document.documentElement.scrollTop + window.innerHeight))
is always larger causing the function to be called non stop and the terminating clearTimeout(timeOutDown)
is never reached.
var timeOutDown;
function scrollToBottom()
{
clearTimeout(timeOut);
if (document.body.scrollHeight > (document.documentElement.scrollTop + window.innerHeight))
{
window.scrollBy(0, 100);
window.external.notify(String(window.innerHeight));
timeOutDown=setTimeout('scrollToBottom()',10);
}
else
{
clearTimeout(timeOutDown);
}
}
What is the correct way to do this considering user can zoom in/out the page?
Solution
Figured it out, just replace document.documentElement.scrollTop
with window.pageYOffset
. So the conditional statement becomes
if (document.body.scrollHeight > (window.pageYOffset + window.innerHeight))
This will take care of the zoom factor.