shortysbest Posted September 19, 2010 Share Posted September 19, 2010 If i have a url that looks like: index.php?node=home#schedule&class=history would there be a way for me to get only the part after the &. for example in php i could use: $_GET['class'] and that would be "history" I'm trying to do the same thing but in javascript with a hash. Quote Link to comment Share on other sites More sharing options...
Alex Posted September 19, 2010 Share Posted September 19, 2010 You can use this: window.location.hash To get the hash, then from that you can create an associative array. Quote Link to comment Share on other sites More sharing options...
Adam Posted September 19, 2010 Share Posted September 19, 2010 I imagine you don't want the hash value to be "schedule&class=history" though..? If you want 'node' to equal "home#schedule" you'll need to encode the hash: index.php?node=home%23schedule&class=history Now you're able to return the query string as you expect it with window.location.search. This post contains an example of how you can return a specific parameter from that. Quote Link to comment Share on other sites More sharing options...
shortysbest Posted September 19, 2010 Author Share Posted September 19, 2010 I imagine you don't want the hash value to be "schedule&class=history" though..? If you want 'node' to equal "home#schedule" you'll need to encode the hash: index.php?node=home%23schedule&class=history Now you're able to return the query string as you expect it with window.location.search. This post contains an example of how you can return a specific parameter from that. Correct, I just want the value "history" such as if i could use php and use $_GET['class'] would return it. I'm building a large website using hash url quite a bit to cut back on header requests as it will be used in every classroom 6 times a day in large schools for grading, attendance, etc. Quote Link to comment Share on other sites More sharing options...
Adam Posted September 19, 2010 Share Posted September 19, 2010 Oh right, sounds like you don't want to encode the hash then. You should be able to just use the example in the other post, but replace .search for .hash. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.