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?
해결되었습니다! 솔루션으로 이동.
조회 수
답글
좋아요 수
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:
조회 수
Likes
답글