I've been searching for hours and have come up empty.
I'm detecting the users scroll position on beforeunload
and saving it to a cookie (using the plugin). After a page refresh the page should now scroll to this position, however it does not.
I can see that the position is saved, and I can also read it inside an alert()
.
scrollTop
works with "hard numbers" but not with the data from the cookie.
parseInt
also doesn't help.
Any ideas why? Thanks a lot in advance!
This code isn't working:
window.onload = function() {
setTimeout(function() {
$(document).scrollTop(300);
}, 100);
this works
vari = $.cookie("scrollTil");
window.onload = function() {
setTimeout(function() {
$(document).scrollTop(vari);
}, 100);
ED:
$(document).ready(function(){
vari = $.cookie("scrollTil");
window.onload = function() {
setTimeout(function() {
$(document).scrollTop(vari);
}, 100);
}
$(window).unload(function(){
$.cookie("scrollTil", $(window).scrollTop());
})
});