4

First of all, thats my current state of play: thsbrk.de.

The black boxes should be e.g. a about section. I want to achieve that if you enter my page (thsbrk.de) you directly go to my reference section (anchor '#references'). Then, if you hit the about link you will scroll up to that about section. I already tried to make it working but it doesn't. The anchor seems to be not working.

It would be awesome if someone could look at my code and offer me a solution :)

(The scroll isn't implemented yet, I only ask for the anchor problem)

EDIT: Here I've got a example how it should work: Example

user1105530
  • 41
  • 1
  • 4

3 Answers3

1

Give a script tag like this in the head.Let it be the first script also.

<script>
location.href="http://thsbrk.de/#references"
</script>

From your code, you have did the same. But just try reordering the script tags it might work.

Kris
  • 8,680
  • 4
  • 39
  • 67
1

Plain JS:

window.onload=function() {
  var anchorHash = 'references';
  document.getElementsByName(anchorHash)[0].scrollIntoView();
}

Here is a jQuery example from 2009 - there may be newer ways

How do I scroll a row of a table into view (element.scrollintoView) using jQuery?

In your case this might work

$(document).ready(function() {
  var anchorHash = 'references';
  var pos = $('#'+anchorHash).position();
  window.scrollTo(0,pos.top);
});
Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236
0

Try this and tell me the result:

$(document).ready(function() {
   window.location.href = '#references';
});

and then modify your anchor tag like this:

<a name="references">Here</a>
Mohammad Saberi
  • 12,864
  • 27
  • 75
  • 127