Accessing Current URL using Prototype

Posted by Jason Nerer on Stack Overflow See other posts from Stack Overflow or by Jason Nerer
Published on 2010-04-14T12:51:23Z Indexed on 2010/04/14 12:53 UTC
Read the original article Hit count: 513

Filed under:
|

Hi folks,

following Ryan Bates Screencast #114 I'm trying to generate endless pages using prototype. In difference to Ryan's showcase my URL called via the AJAX request shall be handled dynamically, cause I do not always call the same URL when the user reaches the end of my page.

So my JS running in backround looks like that and uses document.location.href instead a fixed URL:

var currentPage = 1;

function checkScroll() {
  if (nearBottomOfPage()) {
    currentPage++;
    new Ajax.Request(document.location.href + '?page=' + currentPage, {asynchronous:true, evalScripts:true, method:'get'});
  }
  else {
    setTimeout("checkScroll()", 250);
  }
}

function nearBottomOfPage() {
  return scrollDistanceFromBottom() < 10;
}

function scrollDistanceFromBottom(argument) {
  return pageHeight() - (window.pageYOffset + self.innerHeight);
}

function pageHeight() {
  return Math.max(document.body.scrollHeight, document.body.offsetHeight);
}

document.observe('dom:loaded', checkScroll);

The question is: The code seems to work in Safari but fails in FF 3.6. It seems that FF calculates scrollHeight or offsetHeight differently. How can I prevent that?

Thx in advance. Jason

© Stack Overflow or respective owner

Related posts about prototype

Related posts about ruby-on-rails