get/Set URL hash


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var getHashFromURL = function() {
  2. var r = window.location.href;
  3. var i = r.indexOf("#");
  4. return (i >= 0 ? r.substr(i+1) : "");
  5. };
  6. var setURLHash = function(newhash) {
  7. var url = window.location.href;
  8. url = (!url.match('#'))?url+'#':url.substr(0,url.indexOf('#')+1);
  9. window.location.href = url+newhash;
  10. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.