Reputation: 475
I have the following code below. If I scroll all the way to the right and then reload the page, I expected (based on my javascript code) for the window to scroll all the way to the left. However this does not happen. Please can someone advise?
<html>
<head>
<meta charset="utf-8">
</head>
<style>
#_1{
border: 1px solid blue;
width:1500px;
height: 400px;
}
</style>
<body>
<div id="_1"></div>
</body>
<script>
window.onload = function(){
window.scrollTo(0,0);
}
</script>
Upvotes: 0
Views: 1039
Reputation: 367
I think you may try this?
window.onbeforeunload = function () {
window.scrollTo(0, 0);
}
Or
$(document).ready(function(){
$(this).scrollTop(0);
});
Hope that you like it :)
Upvotes: 1