tags:

views:

27

answers:

2

Hi,

when you click on a link that goes to same page where the link is, how to keep the view of the page?

By default it goes to the top of the same page.

Regards

Javier

+1  A: 

Can you be more specific? What do you mean with "view of the page"?

Here is a general description of anchors:

If you have a link <a href="#someTarget">Link</a> then you need an element on the same page with id="someTarget". When you then click on the link, that element will be scrolled to the top of the element.

EDIT: Ahm, you are talking about a JavaScript link. In that case you need to have the Javascript retur false so that the default action (namely following the link) is ignored:

<a href="#" ... onClick="myJqueryFunction(); return false;">
RoToRa
"view of the page": I mean the vertical position of the page.
Can you describe your problem in more detail?
RoToRa
I have a table (it just shows the head) far from the top of the page. When i click on the head of the table it shows the body of the table, but the view changes to show the top of the page, so i have to go down to see the table again...
I show and hide the body of the table through jquery toggle.
And the link is like this <a href="#" ... onClick="myJqueryFunction()>
+1  A: 

One way to do it is to add # at the end of the href attribute on the links pointing to the current page, either manually or via javascript. I don't think it's a nice way to do it, though...

If you really need this, you could also "disable" the navigation for links pointing to the current page, so that clicking on a link to the current page would have no action...

Something like that should work in jQuery :

$('a.current').click(function(event){
    //cancel default click action
    event.preventDefault();
  }             

assuming that the links pointing to the current page have the CSS class current

tsimbalar