Score:0

Redirect URL path to an action on index?

in flag

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?

Score:3
es flag

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.).

donkey avatar
in flag
This is a great start but it only works for domain.com?q=/schedule whereas I'd like it to work for domain.com/schedule. However when I currently go to domain.com/schedule it correctly says there is no such directory. How can I get that to redirect to my index.html?
es flag
The most simple solution I can think of is defining an alias. Something like `Alias /schedule "/var/www/"`, where `/var/www/` is your current DocumentRoot should work. It basically calls the same directory index, though you should be careful with all your relative paths.
donkey avatar
in flag
Where would I define said alias?
es flag
Either in your _httpd.conf_ or in your virtual host's _conf_ file, preferably before it's corresponding <Directory> section. For example: ``Alias "/schedule" "/var/www" <Directory "/var/www"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>``
Score:0
in flag

At Apache server you can create rewrite rule for rendering the same index.html from another path, but displaying the pop-up widget is something you have to solve at application side (eg. JavaScript can use Web API URL.pathname to detect visiting the domain.com/schedule URL). When your application detects that user visited domain.com/schedule (based on pathname), it can call pop-up widget opening action.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.