Alternative views based on hashtag


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

Show alternative views of your page, depending on a hashtag


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.