Window problem

Hi, I need some help regarding on my page,how can i make my page when i will refresh or ctrl+F5 i want that my vertical scroll bar from the window will be on top so that the middle part of my page will not be seen.because i want by default the scroll bar will always on the top.

Thank you in advance.

Hi jemz,

I was actually surprised at how difficult this was to achieve in a cross-browser compatible way.
The secret was to wrap the call to scrollTop() in a setTimeout(), so that the browser has time to position itself before you reset the scroll position.

Here’s the code:

<!DOCTYPE HTML>
<html>
  <head>
    <!-- http://www.sitepoint.com/forums/showthread.php?977666-window-problem -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Set scrollTop</title>
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    <style>#main{ background:green; height:3000px; width:500px; }</style>
  </head>

  <body>
    <div id="main">
    <h1>Test Div</h1>
    </div>
    <p>Test Paragraph</p>
    <script>
      $(document).ready(function() {
        setTimeout(function() { $("html, body").scrollTop(0); }, 150);
      });
    </script>
  </body>
</html>

You should be able to do it without needing JQuery using the following JavaScript:

setTimeout(function() {window.scrollTo(0,0);},150);

Yup, fair point! :tup:

Thank you felgal :slight_smile:

Thank you pullo :slight_smile: