algorithm Posted December 8, 2010 Share Posted December 8, 2010 i have a link that sends users to another part of the page. How would i store the user's previous position so that they can go back to where they were? Quote Link to comment https://forums.phpfreaks.com/topic/221080-storing-user-position-on-webpage/ Share on other sites More sharing options...
noobstar Posted December 9, 2010 Share Posted December 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221080-storing-user-position-on-webpage/#findComment-1144799 Share on other sites More sharing options...
algorithm Posted December 12, 2010 Author Share Posted December 12, 2010 Yep, that's true, but I was wondering if it was possible to find the vertical position of an anchor, store it in a cookie, and then when needed move back to it Quote Link to comment https://forums.phpfreaks.com/topic/221080-storing-user-position-on-webpage/#findComment-1145968 Share on other sites More sharing options...
RichardRotterdam Posted December 12, 2010 Share Posted December 12, 2010 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'; Quote Link to comment https://forums.phpfreaks.com/topic/221080-storing-user-position-on-webpage/#findComment-1146216 Share on other sites More sharing options...
algorithm Posted December 12, 2010 Author Share Posted December 12, 2010 Almost got it, just need to figure out how to get jquery to move the user's window to a element based on its numerical position, it won't necessarily have an anchor Quote Link to comment https://forums.phpfreaks.com/topic/221080-storing-user-position-on-webpage/#findComment-1146258 Share on other sites More sharing options...
RichardRotterdam Posted December 14, 2010 Share Posted December 14, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/221080-storing-user-position-on-webpage/#findComment-1147091 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.