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!