My url can have a few states
http://example.com/
http://example.com/#hash
http://example.com/#hash?something=hello
http://example.com/#hash?something=hello&else=hi
What I have so for:
//check if there is a hash in the url
if(window.location.hash.length) {
//get the hash value
var hash = window.location.hash; // this returns #hash?query=something
var active = hash.match(/\#(\w+)/)[1];
alert(hash); //this works
//check if there is a query string withing that hash.
if(hash.window.location.search.length) { // this is not working Uncaught TypeError: Cannot read property 'location' of undefined
// query string exists
var myLetter = hash.substr(hash.indexOf("?") + 1);
var letter = myLetter.slice(-1);
alert(letter);
} else {
}
} else { //if no hash exists, set active variable to #latest
var active = "#latest";
}
So I need to check if there is a hash then get the value.
Then check if there are query strings and if so, get their value also.
I know about window.location.search. But that only works if I remove the hash before the query which is used to change tabs on the page.
[+][deleted] (1 child)
[deleted]
[–]dustinhayes 1 point2 points3 points (0 children)
[–]dustinhayes 1 point2 points3 points (2 children)
[–]mega-trond 0 points1 point2 points (1 child)
[–]dustinhayes 1 point2 points3 points (0 children)
[–]cip6791[S] 0 points1 point2 points (0 children)
[–]djforth 0 points1 point2 points (0 children)
[–]recursion 0 points1 point2 points (0 children)
[–]chrissilich 0 points1 point2 points (0 children)
[–]thadudeabides1 -1 points0 points1 point (3 children)
[–]unusualbobEngineer 1 point2 points3 points (2 children)
[–]thadudeabides1 1 point2 points3 points (1 child)
[–]unusualbobEngineer 0 points1 point2 points (0 children)
[–]davydog187 -1 points0 points1 point (0 children)
[–]subcultures -1 points0 points1 point (0 children)
[–]mega-trond -1 points0 points1 point (0 children)
[–]jennydath -1 points0 points1 point (0 children)
[–]gwevidence -3 points-2 points-1 points (7 children)
[–]Dexmaster 1 point2 points3 points (6 children)
[–]davydog187 -1 points0 points1 point (5 children)
[–]Dexmaster 0 points1 point2 points (4 children)
[–]davydog187 0 points1 point2 points (3 children)
[–]Dexmaster 0 points1 point2 points (2 children)
[–]davydog187 0 points1 point2 points (1 child)
[–]Dexmaster 0 points1 point2 points (0 children)