Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var main = document.querySelector('main');
  2.  
  3. function showPage(name) {
  4.   var html = document.getElementById(`t-${name}`).innerHTML;
  5.   main.innerHTML = html;  
  6. }
  7.  
  8. window.addEventListener('hashchange', function() {
  9.   setPageFromHash();
  10. });
  11.  
  12. function setPageFromHash() {
  13.   var hash = window.location.hash.substr(1);
  14.  
  15.   if (hash === 'about') {
  16.     showPage('about');
  17.   } else {
  18.     showPage('home');
  19.   }
  20. }
  21.  
  22. setPageFromHash();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement