The Little Guy Posted October 20, 2008 Share Posted October 20, 2008 If I have a URL like this: http://dudeel.com/#calculate how can I get the text after the pound sign? Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 20, 2008 Share Posted October 20, 2008 Little helper function I have used: <?php //return url hash or empty string function getHash($url){ $pos=strpos($url, "#"); return ($pos !== false) ? substr($url, $pos+1) : ""; } Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 20, 2008 Share Posted October 20, 2008 function getURLParam(URLstr) { return URLstr.replace(/.*#/, ''); } @CroNiX: This is the JavaScript forum. You posted PHP code. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 20, 2008 Share Posted October 20, 2008 Ah, even easier... var hash = document.location.hash; Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 20, 2008 Author Share Posted October 20, 2008 I use this: var curl = document.location; alert(curl.replace(/.*#/, '')); and it redirects me to this page: http://dudeel.com/.*#/ Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 20, 2008 Share Posted October 20, 2008 Nice find on the .hash property - wasn't aware of that one. however, that assumes you are dealing with an object with that parameter value. If the URL is just a text object, it will not have a hash property. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 20, 2008 Share Posted October 20, 2008 function getHashFromURL(url){ var pos=str.indexOf('#'); return (pos!=-1) ? url.substr(pos+1) : ''; } 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.