Search code examples
htmlhyperlinkhref

Make specific href id as set default page


I have a menu bar with 4 id links as shown below. I want the 3rd link to be the default home page when the user visits the site (FAQ) not the 1st as it is now. How can this be done?

 <div class="menu">
    <div class="container">
        <div><a class="0 move" href="#home">Home</a></div>
        <div><a class="2 move" href="#affiliates">Affiliates</a></div>
        <div><a class="3 move" href="#faq">FAQ</a></div>            
        <div><a class="4 move" href="#signup">Sign Up</a></div>
    </div>            
</div>

Solution

  • You can get the current hash and test if it's empty, so you update the hash with javascript. It'll scroll automatically to #faq area

    var url = document.URL, 
        index = url.indexOf("#"),
        hash = index != -1 ? url.substring(index+1) : "";
    
    if(hash === ""){
        location.hash = "#faq";
    }
    

    Here's a fiddle and a second fiddle