history.js - Best way to pass a single-use value between requests using JavaScript -


i need trigger page reload, via js, preserving vertical scroll position.

i'm using solution described in another question:

  1. calculate current scroll position
  2. add current position querystring argument, redirect
  3. when page reloads, read value querystring & adjust scroll pos

however, i want restore scroll position on first redirect. if user scrolls around page , triggers manual reload using ctrl-r, not want re-scroll saved position.

is there way of passing single-use, visible-to-the-next-request-only value using javascript? or removing value document.location.href without redirecting?

should using html 5 history api "clear" position value after i've consumed it?

save value sessionstorage. once use it, delete value cannot read on manual refresh.

sessionstorage.setitem("scroll_position", "300"); sessionstorage.getitem("scroll_position"); // 300 sessionstorage.removeitem("scroll_position"); 

sessionstorage is well-supported -- it'll work fine ie8+ relevant version of other browsers.


stackoverflow handles after-page-load scrolling storing post id's in url hash. well.

the url stackoverflow.com/...../21485393#21485393 has #21485393 matches anchor element <a name="21485393"></a> automatically scroll element after page loads.

you well.

http://your.url.com/page#300 

retrieve with

window.location.hash 

and remove once you're done by

window.location.hash = "" 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -