Jump to content

Storing user position on webpage


algorithm

Recommended Posts

With most browsers I believe as soon as they hit the Back button it sends them back to the previous page plus to the position they were on last automatically.

 

However, if you are referring to being able to flip between positions on the same page then you could use anchor tags and lock those to certain name tags set on particular sections on the page. Here is an example of what I mean:

 

<div name="section1"></div>

<a href="#section1">Section 1</div>

<div name="section2"></div>

<a href="#section2">Section 1</div>

 

Sorry if I wasn't much of a help :(

Link to comment
Share on other sites

You pretty much summed it all up for what you need. All you need to do is search for it how to do it.

but I was wondering if it was possible to find the vertical position of an anchor,

Do a search for "javascript element position"

 

store it in a cookie,

Search for javascript cookies

 

and then when needed move back to it

Read cookie and do something like the following:

window.location.href = 'your_url_here#your_anchor_here';

 

Link to comment
Share on other sites

Here is an example for you:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// place the element into a var
var monkeyButton = $('#monkey');
// fetch the offset (returns object{top, left})
var offset = monkeyButton.offset();
// scroll the windo to the offset
$(window).scrollTop(offset.top);
});
</script>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<button id="monkey">Monkey</button>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.