Redirect URL path to an action on index?

I'm running an apache web server on Ubuntu 20.04.

I have a domain.com which directs clients to the index.html. On the website there is a button that, when clicked, opens a calendal pop-up widget. I would like people who go to domain.com/schedule to land on the index page as if they had clicked that button.

How can I do that simply?


Solution 1:

You definitely need to trigger the pop-up on the client side. Here's a quick sample you can easily try and adjust (and secure) to your needs:

<html>
  <head>
      <script type="text/javascript">
        function isScheduleRequested() {
        if(window.location.href.includes('/schedule')) {
          document.getElementById('button').click();
        }
      }
      </script>
  </head>
  <body onload='isScheduleRequested();'>
      <button type="button" name="button" id="button" onclick="alert('Opening calendar');">Open calendar</button>
  </body>
</html>

What this does is, generally speaking, check if the URL of the current page contains the '/schedule' substring' (anywhere, not necessarily at the end, not even only once), and, if it does, then call the button's click event.

The onload='isScheduleRequested(); bit is just to make sure that the javascript script is executed after the body is loaded (and the button element exists).

You can even try this on your computer. Save this code as "index.html" and open it with your browser. Nothing will happen until you click the button. However if you append ?q=/schedule to the URI, the button's "click" event will be triggered. (In this example we need to pass the /schedule string as part of a GET parameter, since there isn't a domain name, server nor anything fancy set up.).