1

I know you can create a link that will direct you to a section in your website like this

<a href="#result"></a>

But is it possible to set up your website that once it loads up, it automatically goes to the "#result" section? Thank you in advance!

tim_yates
  • 161,005
  • 26
  • 328
  • 327
Eli Davila
  • 547
  • 2
  • 6
  • 14

1 Answers1

1

Yes, you can do it with a bit of JavaScript. Put this in the bottom of your page:

<script>
function jumpTo(anchor){
    window.location.hash = '#' + anchor;
}
jumpTo('result');
</script>

If you have jQuery, you can also make it scroll -- it can make for better usability, cause the user then knows that he is viewing a part of a bigger page:

<script>
function jumpTo(anchor){
    var offset = $('a[name="' + anchor + '"]').offset().top;
    $('html,body').animate({scrollTop: offset}, 'fast');
}
jumpTo('result');
</script>

Related:

Community
  • 1
  • 1
Elias Dorneles
  • 20,592
  • 10
  • 76
  • 100