/    Sign up×
Community /Pin to ProfileBookmark

Refresh the page and scroll down to original position

I am refreshing a page with:

location.reload();

If I am scrolled down on a page, how do I get it so after it refreshes that it scrolls back to the position I was at? Currently, it refreshes and leaves me at the top of the page.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinMar 01.2007 — using purely javascript I can't see a way to do this.

you can set markers in your page and have the page go to them on demand, but as soon as you refresh the page you lose all javascript variables......unless:

you have your page split into 2 frames. The main frame uses 100% of the frame area and the other frame is there to store variables.

I used to use that method occasionally when I needed to store variables globally in javascript, while allowing the user to change page.

As the user scrolls down the page you can keep a check on where they are using properties like: document.documentElement.scrollTop + document.body.scrollTop for IE, or window.scrollY for other browsers.

Then when that frames document changes you run a function stored in the hidden frame that sets the position back as it was...or anywhere you like actually.

This is not a very clean way of doing what you want, but it will work.

Hope this helps.

//erlin!
×

Success!

Help @Scrabble spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...