0

Can I make custom url for using particular event in javascript? For ex. index website has following code and if I type domain.com/menu the website will load with nav-open?

    var navTrigger = document.getElementsByClassName('menu-toggle-click-area')[0],
        body = document.getElementsByTagName('body')[0];

    navTrigger.addEventListener('click', toggleNavigation);

    function toggleNavigation(event) {
        event.preventDefault();
        body.classList.toggle('nav-open');
    }
Pierre
  • 643
  • 1
  • 7
  • 14
  • To answer your question, yes you can. – floverdevel Feb 09 '18 at 21:26
  • 1
    You'll have to [analyze the `window.location`](https://stackoverflow.com/questions/1034621/get-the-current-url-with-javascript) and conditionally open the navigation based on it. – Mikey Feb 09 '18 at 21:34

1 Answers1

0
var path = window.location.pathname.split('/');
if (path.length) {
  var page = path[0];
}

This will store the word menu from your example above into the page variable.

Tallboy
  • 12,847
  • 13
  • 82
  • 173