Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Reload page to same scroller position

Options
  • 16-03-2004 5:27pm
    #1
    Registered Users Posts: 841 ✭✭✭


    Howdy!

    Does anybody know how to reload a page so that it appears at the same scroller position.. In other words, if I am half way down the page and I click a link that refreshes the page (with slight changes), I want the page to refresh and still be scrolled half way down. I am using HTML and JSP..

    Thanks,

    Brian


Comments

  • Moderators, Politics Moderators Posts: 39,950 Mod ✭✭✭✭Seth Brundle


    I think that if you refresh a page it should load in same place again
    so maybe a JavaScript link like the following may work?
    <A HREF="JavaScript:window.location.reload">Refresh Page</A>


  • Moderators, Politics Moderators Posts: 39,950 Mod ✭✭✭✭Seth Brundle


    I forgot a set of brackets () after reload in last post but this isn't what you want anyway.
    Try this:-
    <A HREF="javascript:history.go(0)">refresh the page</A>


  • Registered Users Posts: 841 ✭✭✭Dr Pepper


    Thanks kbannon! But, unfortunately it's a bit more complicated than that... Hmm it's a long story.
    - There is a page called selectSong.jsp
    - There is a form on the left of this page to select songs.
    - There is a shopping basket on the right to display all the selected songs.
    - The link I am talking about is the submit button of the form. This link to another jsp page (addToBasket.jsp) which is not displayed. This page adds the song to the shopping basket (Database stuff) and then links stright back to the origional page.

    So, I suppose the only way to do it is if you could get the current scrolled position of selectSong.jsp, store it as a session variable (or whatever) and then scroll the page to this postion when it is recalled from addTOBasket.jsp..

    Basically.. Is there any way to
    - get the position of the page as an int let say when a submit button is pressed (using jsp, Javascript)
    - scroll a page to a position when it is loaded


  • Closed Accounts Posts: 135 ✭✭dynamic.ie


    I'm going to make a couple of assumptions about what you're working with. On each row that has a submit button, place the following:

    <a href="1"></a>

    Then the next row:

    <a href="2"></a>

    And the next row:

    <a href="3"></a>

    And so on.

    Then for each form that you have a submit button, put a hidden field beside it with the number of the row corresponding to the above. e.g.

    <input type="hidden" name="position" value="1">

    Then when the form is submitted, use your serverside code to do whatever processing and then redirect to:

    selectSong.jsp#3

    Where 3 is the value you pull from the hidden field in the submitted form.

    If you're using a database and a repeat region to create your rows, then it should be quite easy to write a little script to do all this automatically on the serverside. e.g. in ASP it would look something like this but you could re-write for JSP.

    <% rowcount = rowcount + 1 %>

    <a href = "<% = rowcount %>></a>

    <input type="hidden" name="position" value="<% = rowcount %>">


    Does that make sense?

    Best of luck,

    Dave


  • Registered Users Posts: 841 ✭✭✭Dr Pepper


    Thanks a mil dynamic!

    I think I get the jist of it now alright.. I won't have a minute to try this out till next week so I'll let ya know how it goes then..

    Thanks again,
    Brian


  • Advertisement
Advertisement