Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving screen position -- 1

Status
Not open for further replies.

link9

Programmer
Nov 28, 2000
3,387
US
Hello all --

I have a sort of off the wall question, but what the heck...

I have this page that has a battery of select boxes, text boxes, radio buttons, etc... and they are used to enter information into a database about projects -- the page reloads each time a selection is made, checking their inputs against the database each time -- enforcing business rules as it goes --

Here's the problem, though. When the page reloads, it of course resets itself back to the top of the page --

I know I could use anchors to set the page back, but depending on screen res and whether or not they had the element they are working on right at the top of the screen (and probably a few others), having the screen reload and then anchor to something probably wouldn't be my best solution -- I'd rather just not have it at all if that's all I can do --

So the question is -- is there some way to save the actual screen position, and then have the browser re-orient itself to the exact same position on reload??? Just like the back button on your browser -- it does it -- when you hit back, it goes back to the exact same spot that you left that page

Anyone know how I could replicate that?? (and I'm not looking for history.back)

Thanks for any input! :)
Paul Prewett
 
When you submit your form - or just before you do, go and get the scrollTop value for the page, and append it to your query string - by making it a hidden value in your form.

These values get sent harmlessly to your action handler - then just have them get sent back - a small modification to your server response. The all you need on your page is something which checks for the query string - and uses it onLoad - or just after the body tag is read, to set the scrollTop again.

let me know if it works :-Q
b2 - benbiddington@surf4nix.com
 
I have tried this with asp, and it works, though I had to put this piece at the end of the body:

<%
scrollValue = Request.QueryString(&quot;scrollTop&quot;)
Response.write &quot;<script>&quot;
Response.write &quot;document.getElementById('body').scrollTop=&quot; & scrollValue & &quot;</script>&quot;
%>


This just means that your page will load, and then scroll itself, which shouldn't be a problem, unless the page is large. Perhaps you might try onLoad or something, but you get the idea right?
b2 - benbiddington@surf4nix.com
 
Ok, now how do I get that value?? .scrollTop

I tried setting it like:
= document.getElementById('body').scrollTop

but I get an 'object expected' error --

thx
paul
 
I figured it out --

you can just say:

document.body.scrollTop to both get and assign the values --

thx again
 
Oh, sorry - and also, you may find that if the scrollbar is at it's maximum, i.e. bottom of page - you get it jumping up a bit? By putting that asp bit in onLoad, that is solved.
b2 - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top