In our AEM website, we want to display a “Leaving Website” page when a user is leaving our domain. What would be the recommended way to code this?
Solved! Go to Solution.
Views
Replies
Total Likes
You can achieve this by using JavaScript to detect when a user clicks on
any Button
any Anchor / Navigation link
CTA button click
closing the browser window -- that leads to a different domain.
except closing the window - remaining three has configured with new domain URL.
you can write a Javascript
sample
document.querySelectorAll('a').forEach(function(link) {
link.addEventListener('click', function(event) {
var linkhasOtherDomain = link.hostname;
var currentDomain = window.location.hostname;
if (linkhasOtherDomain !== currentDomain) {
event.preventDefault();
var userConfirmation = confirm('You are leaving our website. Are you sure you want to continue?');
if (userConfirmation) {
window.location.href = link.href;
}
}
});
});
for window close event - write a different condition.
You can achieve this by using JavaScript to detect when a user clicks on
any Button
any Anchor / Navigation link
CTA button click
closing the browser window -- that leads to a different domain.
except closing the window - remaining three has configured with new domain URL.
you can write a Javascript
sample
document.querySelectorAll('a').forEach(function(link) {
link.addEventListener('click', function(event) {
var linkhasOtherDomain = link.hostname;
var currentDomain = window.location.hostname;
if (linkhasOtherDomain !== currentDomain) {
event.preventDefault();
var userConfirmation = confirm('You are leaving our website. Are you sure you want to continue?');
if (userConfirmation) {
window.location.href = link.href;
}
}
});
});
for window close event - write a different condition.
Follow below link for more details and easy implementation:
Views
Likes
Replies