Home News Contact Us Forum About Us Demos Products F.A.Q.
Shopping Cart
You currently have 0 items in your cart.


Recent Events
  • 23/11/2024 Black Friday 2024

    BIG SALE, 30% discount for all our extensions. Use BF24 coupon code. Hurry up the discount is valid till 3 December.

  • 31/12/2023 New Year SALE

    We are glad to announce New Year SALE. 25% discount for all our extensions. Use NY24 coupon code. Hurry up the discount is valid till 7 January.


2Checkout.com, Inc. is an authorized retailer of goods and services provided by ARI Soft. 2CheckOut




Follow us on twitter



Welcome, Guest
Please Login or Register.    Lost Password?

Link Content doesn't open when iframe is forbidden
(1 viewing) (1) Guest
"ARI Fancy Lightbox" WordPress plugin
Go to bottomPage: 1
TOPIC: Link Content doesn't open when iframe is forbidden
*
#72117
Link Content doesn't open when iframe is forbidden 4 Months, 4 Weeks ago Karma: 0
When using ARI Fancy Lightbox setting 'Open external links into lightbox' > 'Convert links' (checkbox) it converts external links to open in lightbox which is pretty cool. However there is a huge number of websites that prevent showing in an iframe. They add to their .htaccess file:
Code:

header set x-frame-options SAMEORIGIN


Many links on a given page show the following message on click:

To protect your security, x.com will not allow Firefox to display the page if another site has embedded it. To see this page, you need to open it in a new window.

It would be handy if 'Open external links into lightbox' had an event to check if the website allows loading into an iframe. If the website does not open in an iframe would be good if we simply open the link in a new tab or open the link. In the current implementation many links open blank lightbox's with the security notice which isn't ideal for users and may be bad for SEO. Here's a few iframe checkers people have made:

stackoverflow.com/questions/12267010/how-can-i-detect-whether-an-iframe-is-loaded#answer-12267180

stackoverflow.com/questions/9249680/how-to-check-if-iframe-is-loaded-or-it-has-a-content/10444444#10444444
Last Edit: 2024/07/26 23:24 By Josh.
The administrator has disabled public write access.
 
#72123
Re:Link Content doesn't open when iframe is forbidden 4 Months, 3 Weeks ago Karma: 760
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
The administrator has disabled public write access.
 
#72124
Re:Link Content doesn't open when iframe is forbidden 4 Months, 3 Weeks ago Karma: 0
I'll bookmark this topic. Hoping to get better at JavaScript in the coming months. I appreciate the investigation/code sample.
The administrator has disabled public write access.
 
Go to topPage: 1