For compatibility on all browsers, try [this method][1]
function getDocHeight() {
var D = document;
return Math.max(
D.body.scrollHeight, D.documentElement.scrollHeight,
D.body.offsetHeight, D.documentElement.offsetHeight,
D.body.clientHeight, D.documentElement.clientHeight
);
}
Replace `$(document).height()` by this function and it's all good
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == getDocHeight()) {
alert("bottom!");
}
});
[1]: https://j11y.io/javascript/get-document-height-cross-browser/
Nick Craver's answer works fine, spare the issue that the value of `$(document).height()` varies by browser.
To make it work on all browsers, use this function from [James Padolsey][1]:
function getDocHeight() {
var D = document;
return Math.max(
D.body.scrollHeight, D.documentElement.scrollHeight,
D.body.offsetHeight, D.documentElement.offsetHeight,
D.body.clientHeight, D.documentElement.clientHeight
);
}
in place of `$(document).height()`, so that the final code is:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == getDocHeight()) {
alert("bottom!");
}
});
[1]: http://james.padolsey.com/javascript/get-document-height-cross-browser/