Newsletter
admin2024-10-07T09:58:22+02:00
(function() {
// === Αναχαίτιση checkout → άνοιγμα στο external browser ===
function sendExternal(url) {
window.parent.postMessage({ type: 'openExternal', url: url }, '*');
}
function isCheckout(url) {
try {
return new URL(url, window.location.href).pathname
.replace(/\/+$/, '').endsWith('/checkout');
} catch(e) { return false; }
}
document.addEventListener('click', function(e) {
var a = e.target && e.target.closest ? e.target.closest('a') : null;
if (a && a.href && isCheckout(a.href)) {
e.preventDefault(); e.stopPropagation();
sendExternal(a.href); return false;
}
}, true);
try {
var origAssign = window.location.assign.bind(window.location);
window.location.assign = function(url) {
if (isCheckout(url)) { sendExternal(new URL(url, window.location.href).href); return; }
origAssign(url);
};
var origReplace = window.location.replace.bind(window.location);
window.location.replace = function(url) {
if (isCheckout(url)) { sendExternal(new URL(url, window.location.href).href); return; }
origReplace(url);
};
} catch(e) {}
// === goBack από native ===
window.addEventListener('message', function(e) {
if (e.data && e.data.type === 'goBack') {
if (window.history.length > 1) {
window.parent.postMessage({ type: 'wentBack' }, '*');
window.history.back();
} else {
window.parent.postMessage({ type: 'cannotGoBack' }, '*');
}
}
});
// === Spinner κατά αλλαγή σελίδας ===
window.addEventListener('beforeunload', function() {
window.parent.postMessage({ type: 'navigationStart' }, '*');
});
// === Εξωτερικά links → άνοιγμα στο browser ===
var allowedHost = 'komninostravel.gr';
document.addEventListener('click', function(e) {
var a = e.target && e.target.closest ? e.target.closest('a') : null;
if (!a || !a.href) return;
try {
var host = new URL(a.href).hostname.replace(/^www\./, '');
if (host !== allowedHost) {
e.preventDefault(); e.stopPropagation();
window.parent.postMessage({ type: 'openExternal', url: a.href }, '*');
}
} catch(e2) {}
}, true);
})();