Hello,
It is browser security feature to disable some remote content based on CORS rules. It is possible to run a script before opening a remote content into the lightbox, but a quick research doesn't help to find a solution how to detect such links in javascript. The following code can be added to "Custom JS code" parameter on "ARI Fancy Lightbox -> Settings -> Advanced" page as a start point. Need to change implementation for isValidUrlForIframe() function to detect not valid links:
Code: |
function isValidUrlForIframe(url) {
var status$ = $.Deferred();
var ifr = document.createElement('iframe');
ifr.onload = function() {
try {
const doc = ifr.contentDocument || ifr.contentWindow.document;
const html = doc.body.innerHTML;
status$.resolve(html !== null && html !== '');
} catch(err) {
status$.resolve(false);
}
};
ifr.onerror = function() {
status$.resolve(false);
}
ifr.src = url;
ifr.style.display = 'none';
document.body.appendChild(ifr);
return status$.promise();
}
setTimeout(function() {
$('.ari-fancybox-iframe').each(function(i, el) {
el.addEventListener('click', function(ev) {
var $el = $(this),
status = $el.data('check-status');
if (status === 'completed') {
var res = $el.data('check-res', res);
if (!res) {
ev.stopImmediatePropagation();
ev.preventDefault();
return false;
}
return;
}
if (status !== 'running') {
$el.data('check-status', 'running');
var url = $el.attr('href');
isValidUrlForIframe(url).then((res) => {
$el.data('check-status', 'completed');
$el.data('check-res', res);
if (res) {
$el.click();
}
});
}
ev.stopImmediatePropagation();
ev.preventDefault();
return false;
}, true);
});
});
|
BTW, no-lightbox CSS class can be added to links which should be ignored by the lightbox.
Regards,
ARI Soft