The modal I've developed appears when a visitor lands on our website through an external link (such as from a Google search result). However, an error occurs and the modal fails to show up if the user manually types our URL into the address bar.
Below is the code snippet:
const siteUrl = ["website.com"];
const referrer_hostname = new URL(document.referrer).hostname;
if (siteUrl.includes(referrer_hostname)) {
console.log("Don't Show Modal", document.referrer);
} else {
console.log("Show Modal", document.referrer);
$( window ).on('load', function() {
console.log("closure modal firing");
$('#closureModal').modal({
backdrop: 'static',
keyboard: false,
show: true
});
});
The #closureModal
element is linked to the HTML structure of the modal.
Error:
(index):123 Uncaught TypeError: Failed to construct 'URL': Invalid URL