Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. /**
  2. * getHash of location url
  3. *
  4. * @param {boolean} exclude_get - hash = substing from # to ?
  5. * @param {string} regex
  6. * @method getHash
  7. * @return
  8. * @usage Tc.Utils.Globals.getHash(true,/^[a-z0-9_\.-]*$/i)
  9. */
  10.  
  11. getHash: function(exclude_get,regex) {
  12. var hash = window.location.hash
  13. ,no_get = (typeof no_get !== 'boolean')? true : no_get
  14. ,stop = no_get ? hash.indexOf('?') : -1
  15. ,hashval // init
  16. ;
  17.  
  18. // if there was no question mark in the hash, or no_get parameter is set to false
  19. hashval = (stop == -1)
  20. ? hash.substring(1) // remove #
  21. : hash.substring(1,stop) // remove # and exlude everything after '?'
  22. ;
  23.  
  24. // security check: check if hash match regex
  25. if (regex) hashval = regex.test(hashval) ? hashval: '';
  26.  
  27. return hashval;
  28. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement