1

I want to add a hashtag (#) in all pages, the reason is that the header height is too long, and I don't want the user to scroll down every time the page loads to see the content of the page.

I have added a link called "hash" so that the page will point to the title page instead

<!-- Page Title -->
<div class="flexslider">
    <a name="hash"></a>
    <div class="titlepage"><h2>{{ $page_title }}</h2></div>    
</div><!--/flexslider-->
<!-- End Page Title -->

I am using Laravel 4, not sure if Laravel has a function to append it to all URL e.g. my_project/employee#hash

lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
Paengski
  • 339
  • 2
  • 6
  • 15

1 Answers1

0

There are two different approaches. (Disclaimer: I'm using jQuery here, not pure javascript)

1. Add the hash to every link

$(document).ready(function(){
    $('a[href]').each(function(){
        $(this).prop('href', $(this).prop('href')+'#hash');
    });
});

2. Add the hash to the current page

$(window).load(function(){
    window.location.hash = 'hash';
});

With the second method instead of just setting the hash you could also use javascript to scroll down with an animation. Like described here (without the click handler)

Community
  • 1
  • 1
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270