const shareButton = document.querySelector('[data-share="true"]');
if (shareButton) {
shareButton.addEventListener('click', function(event) {
event.preventDefault();
const pageUrl = window.location.href;
const pageTitle = document.title;
const pageText = "Check out this amazing accommodation!"; // Customize this text
// Check if the Web Share API is available
if (navigator.share) {
navigator.share({
title: pageTitle,
text: pageText,
url: pageUrl
}).then(() => {
console.log('Successfully shared!');
}).catch((error) => {
console.log('Error sharing:', error);
});
} else {
// Fallback for browsers that don't support the Web Share API
// Here you can implement a custom pop-up with social media links.
// For simplicity, we'll just copy the URL to the clipboard.
navigator.clipboard.writeText(pageUrl).then(() => {
alert('Link copied to clipboard!');
}).catch((error) => {
console.error('Failed to copy link: ', error);
});
}
});
}
});
Update cookies preferences