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 7513419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:10:52+00:00 2026-05-30T00:10:52+00:00

I am trying to find the string after the my hash sign so when

  • 0

I am trying to find the string after the my hash sign so when the user reloads the page I can just look at that string and then load the correct page dynamically. My url looks like this http://mysite.com/#!/account/. How do I retrieve just the /account/? I have tried using this:

var oldLoc = window.location,
patt = /#!(.+)/,
newLoc = oldLoc.match(patt)[1]; // This returns `/account/settings`

if (newLoc == '' || newLoc == '#!/' || newLoc == '/#!' || newLoc == '/#!/') {
    $('#reload_section').load('main.php');
} else if (newLoc == '/newsfeed/') {
    $('#reload_section').load('newsfeed.php');
} else if (newLoc == '/account/') {
    $('#reload_section').load('account.php');
} else if (newLoc == '/search/') {
    $('#reload_section').load('ajaxsearch.php');
}

This works fine if I put a value like http://mysite.com/#!/account/ inside the oldLoc variable but if I put what I have it gives me this error:

TypeError: 'undefined' is not a function (evaluating 'oldLoc.match(patt)')

1)Why doesn’t this work, I have tried all different combinations window.location, document.location, nothing works.
2) Is there an easier way to find what the hash is of the page and then load the correct page as shown above?

Thanks!

  • 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-30T00:10:53+00:00Added an answer on May 30, 2026 at 12:10 am

    Use window.location.hash. For the URL http://mysite.com/#!/account/, it will return #!/account/. Now, simply take the #! off of the front with a regular expression:

    window.location.hash.replace(/^#\!/,"")
    

    The above code will give you /account/.

    EDIT: You could also use this:

    window.location.hash.substring(2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find the amount of space/width that a string would take when
I'm trying to find a Delphi function that will split an input string into
Trying to filter the results after a query. Need to find a string inside
i'm trying to find out if a string value EndsWith another string. This 'other
I'm trying to find all permutations of a string and sort them alphabetically. This
I'm trying to find the easiest way to search a string for an array
I'm trying to find a way to break a string at the second last
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
I'm trying to find the positions of all occurrences of a string in another
After spending a good 3 to 4 hours on google trying to find any

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.