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

  • Home
  • SEARCH
  • 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 4064884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:54:48+00:00 2026-05-20T15:54:48+00:00

Ok, I have this script working 99% of how it should be working, but

  • 0

Ok, I have this script working 99% of how it should be working, but I can’t seem to figure out this little bit.

When the user clicks on a link it takes the href value and chops it up and gives me the last segment of the url. In this example I’ll say its home

so my script then grabs home and adds it to the url in the address bar.
so it look like http://www.site.com/user/s2xi/home after its done doing its magic.

But originally I had an issue where because of the nature of how links work I suppose it would keep appending my url like this http://www.site.com/user/s2xi#/home which on my server doesn’t exists

So I was able to get rid of the # and it got everything back to normal…oh wait, no not everything always works perfect on the first try…

so i then realized that my script was appending link names instead of replacing them… oh noes, now what?

my links would now look like this: http://www.site.com/user/s2xi/home/someOtherLink

it would append the new link name to old link name instead of replacing it…

my script:

var newHash    = "",
        shref      = "",
        content    = '#content',
        $c         = $("#content"),
        $cw        = $("#content-wrapper");

    $(".menu-link, #my-account-link").live('click', function(){
        shref = $(this).attr("href").split("/");
        parent.location.hash = $(this).attr("href");
        window.location.hash = shref[5];
        console.log(window.location.hash);
        return false;
    });

    $(window).bind('hashchange', function(){
        if (location.href.indexOf("#") > -1) {
            location.assign(location.href.replace(/\/?#/, "/"));
        }
        newHash = window.location.hash;
        //newHash = window.location.hash.substring(1);
        //newHash = window.location.substring(1);
        //console.log(newHash);
        if(newHash)
        {
            $cw.find(content).fadeOut(200, function() {
                $cw.load(newHash + " #content-wrapper", function() {
                    $c.fadeIn();
                });
            });
        }
    });
    $(window).trigger('hashchange');

what could be wrong with the script logic?

  • 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-05-20T15:54:48+00:00Added an answer on May 20, 2026 at 3:54 pm

    First, without /.../g, you’re just replacing the first match, which may be what you want.

    You logic seesm to be:

    1. Replace # with link, so the hash now becomes a link
    2. When you click on a link, the handler takes the last segment in the current href attribute and put it into a hash. Notice that you have not removed that segment from the url.

    In other words, say it starts with:

    http://www.site.com/user/s2xi

    You href, say, is http://www.site.com/user/s2xi/home. Then on your click, you get shref[5] = “home”. And you add it to hash of the current url, which makes it:

    http://www.site.com/user/s2xi#home

    And then you convert that hash back into a link:

    http://www.site.com/user/s2xi/home

    All is fine. The second time you click on a link, say, http://www.site.com/user/s2xi/foo. On your click, shref[5] = “foo”.

    You then add it to your hash of the current url:

    http://www.site.com/user/s2xi/home#foo

    Then you convert that hash back into a link:

    http://www.site.com/user/s2xi/home/foo

    Voila. You appened the link instead of replacing it. You should be replacing the segment in the url.

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

Sidebar

Related Questions

I'm sure this is really simple, but I can't seem to get it working.
I have this script: select name,create_date,modify_date from sys.procedures order by modify_date desc I can
I have this little script to toggle a contact form when a button is
I have this bit of script to widen a text box on mouseover and
Well basically I have this script that takes a long time to execute and
I have this Perl script with many defined constants of configuration files. For example:
I have this .bat script which I use to maven package my application. Problem
I have this simple php script <?php echo '<pre>'; // Outputs all the result
I have this line in a useful Bash script that I haven't managed to
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The

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.