views:

32

answers:

2

Hi guys,

I have the following question/problem:

On this page http://www.projectyou.gr/gp/?page_id=5 there are 3 tabs
[It's all in Greek but I hope you will understand]
Each tab contains links to articles.
When you click on an article and then press the back button on the browser it comes back to the selected tab AND scrolls to the article you clicked.
As much as I like this behavior it is not what I want in this case.
I would like the user, when returning to the page, always go to the top.

What is the best way to achieve this.
Does it have to do with the fact that I'm using jQuery tabs and the code that I have for returning to the previously selected tab causes to jump to previously clicked anchor??

Any help would be very much appreciated.
Thanks

+2  A: 

how about adding something such as this to your document ready handler (I realize you may already have one, so just appending the scrollTo might do it):

$(document).ready(function() {
  window.scrollTo(0, 0);
});

like in this SO question

Yoni H
This works, thanks a lot. Just did it. However it seems like it goes down and then up. There is a small latency ... it would be great if we could find a solution to prevent that behavior. Thanks a lot anyway
ion
well... instead of scrolling at the end of the ready handler, you could try and sneak it in a "normal" <script> block, although I really don't know if that will work.
Yoni H
A: 

You could also use

$("html:not(:animated),body:not(:animated)").animate({ scrollTop: 0}, 500 );

which scrolls it in an animated way, The 500 is the speed in milliseconds

the 0 is how from from the top of the page,

if you wanted to scroll to the top of an element you could replace it with

var offset = $('element').offset();
var top = offset.top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: top}, 500 )

;

Hailwood