I have a booking form on my website that when clicked, opens a form in a new window for the user to fill out to book a table, when the form is complete, the window is closed.
The problem is, I want the form to ONLY be accessed from this button on the homepage (Or just any button from the homepage). What I want to stop though, is users being able to access /booking directly without interacting with the homepage at all.
The behaviour I would like is
If a user clicks a button on the homepage, it should open the form with a window.open command (already implemented) and the user can fill out the form no problem.
IF the user simply types into the url www.DOMAIN.com/booking, it should recognise they are haven't accessed this page from the main page and just re-direct them back to www.DOMAIN.com.
Here is my current attempt at this.
Booking.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Booking</title>
</head>
<body>
<div id="booking-form">
</div>
<script>
const myReferrer = document.referrer;
const hasReferrer = document.referrer != "";
const bookingFormArea = document.getElementById('booking-form')
if(hasReferrer) {
bookingFormArea.innerHTML=`<div id="rd-widget-frame" style="max-width: 600px; margin: auto;"></div>` // LOAD BOOKING FORM
} else {
bookingFormArea.innerHTML=`window.location.href = 'www.DOMAIN.com';` //Re-direct User to homepage
}
</script>
</body>
</html>
UPDATE: Upon further testing, it seems that by using a button to link to "/booking" through a 'onClick' method and also using 'window.open' for it, document.referrer still comes up blank, is this correct behaviour?