According to this document.body.scrollTop
is deprecated in firefox try document.documentElement.scrollTop
instead. You may have to insert some conditional logic to use document.body.scrollTop
in Safari and document.documentElement.scrollTop
in firefox.
Change your click handler to something like
$("#english").on("click",function(){
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
localStorage.setItem("scroll", scrollTop);
});
ALSO
If scroll does not exist in localStorage then
localStorage.clear();
typeof localStorage.getItem("scroll"); // "object"
If scroll exists then
localStorage.setItem("scroll", 1000);
typeof localStorage.getItem("scroll"); // "string"
If scroll is 0
localStorage.setItem("scroll", 0);
typeof localStorage.getItem("scroll"); // "string"
thus, unless "scroll" is explicitly set to undefined, typeof
localStorage.getItem('scroll') === 'undefined';
will never return true.
If scroll does not exist, its value is null
localStorage.clear();
localStorage.getItem("scroll"); // null
AND
null === true //false
so
if(localStorage.getItem("scroll"))
{
window.scrollTo(0, parseInt(localStorage.getItem("scroll")));
}
will scroll if scroll exists (and is a number of course) and won't if it does not. Are you looking for some other behavior?