I am not able to get redirected when using lightbox with google maps and apple maps. Can someone help. I have included the lightbox code below. Also how can i make the text look even. Below is the code that I am using.
Regards,
Robin
import wixWindow from ‘wix-window’;
$w.onReady(function () {
const address = “2828 1st Ave, Huntington WV 25702”;
const encodedAddress = encodeURIComponent(address);
const googleMapsUrl = `https://www.google.com/maps?daddr=${encodedAddress}`;
const appleMapsUrl = `https://maps.apple.com/?daddr=${encodedAddress}`;
// Safe hide on load
if ($w("#redirectingText")?.hide) $w("#redirectingText").hide();
if ($w("#spinnerIcon")?.hide) $w("#spinnerIcon").hide();
if ($w("#googleMapsBtn")?.show) $w("#googleMapsBtn").show();
if ($w("#appleMapsBtn")?.show) $w("#appleMapsBtn").show();
$w("#googleMapsBtn").onClick(() => {
redirectWithAnimation(googleMapsUrl);
});
$w("#appleMapsBtn").onClick(() => {
redirectWithAnimation(appleMapsUrl);
});
function redirectWithAnimation(mapUrl) {
if ($w("#googleMapsBtn")?.hide) $w("#googleMapsBtn").hide();
if ($w("#appleMapsBtn")?.hide) $w("#appleMapsBtn").hide();
if ($w("#mapsTitleText")?.hide) $w("#mapsTitleText").hide();
if ($w("#redirectingText")?.show) $w("#redirectingText").show();
if ($w("#spinnerIcon")?.show) $w("#spinnerIcon").show();
setTimeout(() => {
const newTab = window.open(mapUrl, "_blank");
// Fallback if browser blocks popup
if (!newTab || newTab.closed || typeof newTab.closed === 'undefined') {
const fallbackLink = document.createElement('a');
fallbackLink.href = mapUrl;
fallbackLink.target = "_blank";
fallbackLink.rel = "noopener noreferrer";
fallbackLink.click();
}
wixWindow.lightbox.close();
}, 700);
}
});