I have a web page which reloads some data using a jquery post every 30 seconds, the jquery post will will retrieve the anchors in a tab form so when the jquery does the refresh the anchor is always put to the first anchor.
Let's say I have #anchor1, #anchor2 and #anchor3. If the user is viewing #anchor2 and jquery reloads, it defaults to #anchor1. Before the jquery is done I check to see which anchor the viewer is using, and then after jquery has finished I then select the anchor that they were looking at by using the code below
document.location.href= "#anchor2";
When I use the above code it obviously causes the page to refresh so it then does the initial document.ready function to retrieve the data, so therefore the timer never gets used, it just instead permanently keeps reloading the jquery, doing it every second or so instead of using the javascript timer.
How can I direct the user to the anchor that the user was looking at before the ajax reload without causing the page to refresh.
Thanks for any help you can provide.
Use the document.location.hash
property:
document.location.hash = "#anchor2";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With