Posted By

jbernus on 06/27/13


Tagged

javascript hashtag


Versions (?)

Alternative views based on hashtag


 / Published in: JavaScript
 

Show alternative views of your page, depending on a hashtag

  1. /* URL sample: http://bla.com/#altview */
  2.  
  3. var altviews = {
  4.  
  5. hashTagTrigger : function(){
  6. var hash = location.hash;
  7.  
  8. if(hash){
  9. var hash = hash.replace(/^#/, '');
  10.  
  11. if(this[hash])
  12. this[hash].init();
  13. }
  14. },
  15.  
  16. altview : {
  17. init : function(){
  18. this.css();
  19. this.js();
  20. },
  21.  
  22. css : function(){
  23. $('body').addClass('alt-view');
  24. },
  25. js : function(){
  26.  
  27. }
  28. },
  29.  
  30. altview1 : {
  31. init : function(){
  32. // Do something
  33. }
  34. }
  35.  
  36. }
  37. altviews.hashTagTrigger();

Report this snippet  

You need to login to post a comment.