Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:51:24+00:00 2026-06-10T15:51:24+00:00

I have a menu that loads a new html file in a div. The

  • 0

I have a menu that loads a new html file in a div. The loading is done by a click event attached to the menu’s <a> tags. The loading works well and I add the new load to the history by constructing a new href with a hash tag.

But when I use the back button, the URL is updated correct in the browsers address field, but the page is never loaded. If I focus the address field and press enter it loads.

This is the javascript located in the mypage.html header.

<script type="text/javascript">
  $(document).ready(function() {

    // replace menu link click
    $(".right-menu a").live('click', function(ev) {
      ev.preventDefault();
      ev.stopPropagation();
      window.location.href = $(this).attr('href');
      $("#content-right").load('mypage'+window.location.hash.substring(1)+'.html');
      return false;
    });

    // If page loads, load the content area according to the hash.
    var hrtag = window.location.hash.substring(1);
    if(hrtag=="")
      hrtag='about';
    $("#content-right").load('mypage'+hrtag+'.html');
    window.location.hash = hrtag;
  });
</script>

This is the menu

<ul class="right-menu">
  <li><a href="mypage.html#about">About</a></li>
  <li><a href="mypage.html#screens">Screens</a></li>
  <li><a href="mypage.html#license">License</a></li>
  <li><a href="mypage.html#download">Download</a></li>
  <li><a href="mypage.html#donate">Donate</a></li>
</ul>

If I load the page as mypage.html, the javascript will append the hash #about and load the div id "content-right" with mypageabout.html

If I click the menu, for example download, it will load the div id "content-right" with mypagedownload.html

In both cases, the window.location will be set to the hash version of the page, mypage.html#about and mypage.html#download to register them in the history.

If i click the menu in the following order; license, about, screens and then click the browser’s back button, the address field will show; mypage.html#about, mypage.html#license but it will NOT load the pages!?!

The URLs are obviously in the history, but they don’t load.
Any clue to what might be wrong here?

// Thanks

EDIT – The solution

Thanks to Andres Gallo’s article I came up with this solution:

<script type="text/javascript">
  $(document).ready(function() {

    // Make sure the page always load #about
    LoadIDWithURL('#content-right','myPageAbout.html');

    window.addEventListener('hashchange',function() {

      if (window.location.hash != "") {
        // We have a hash, use it!
        LoadIDWithURL('#content-right','MyPage'+window.location.hash.substring(1)+'.html');
      } else {
        // We do not have a hash, force page reload!
        window.history.go(0);
      }

    });

  });

  // Load the targetID with the URL loadURL.
  function LoadIDWithURL(targetID,loadURL) {
    $(targetID).load(loadURL);
  }
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:51:26+00:00Added an answer on June 10, 2026 at 3:51 pm

    I wrote a very detailed article on this exact topic. It explains how to build exactly what you are trying to do.

    Furthermore my article also explains how you can pass parameters in your links to have javascript do special things

    Here is a link to the article http://andresgallo.com/2012/06/08/ajaxifying-the-web-the-easy-way/

    The best method is to attach your functionality to your hashchanges rather than to you click events. This allows any changes in history to take advantage of your javascript functionalities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a menu that if you click it it loads external content then
i have a menu that contains just one item. Button exit; @Override public boolean
I have a menu that uses SSIs, problem is the tag needs an id
I have a menu that changes and I want to show content in the
I have a menu that looks something like this: <MenuItem x:Name=menu ItemsSource={Binding Items} Style={StaticResource
I have a menu that will return 'e' unless the input is d or
My ultimate goal is to have a menu that adds a class to the
So on my page I have a menu that is fixed to the top
I have a dropdown menu that pulls in text from a database column. The
I have a dropdown menu that I am using and can't quite get it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.