PDF on iPad and iPhone

Forums Easy FancyBox Pro PDF on iPad and iPhone

Tagged: ,

Viewing 7 reply threads
  • Author
    Posts
    • #4782
      Richard Barnhart
      Participant

      When I try to open a pdf in fancybox on iPad or iPhone it just opens a blank box, the pdf does not load. Is there a setting that will make it responsive and available on mobile devices.

    • #4789
      RavanH
      Keymaster

      To view a PDF file in a browser, you need a PDF reader browser plugin. iDevices are known to not have that preinstalled nor is such a plugin available. The only solution is to use an external PDF viewer solution.

      Something like the alternative method #2 on http://demo.status301.net/easy-fancybox-sandbox/pdf-embeds but I cannot tell you for how long Google will continue to allow displaying of files outside those hosted on Google Drive… Underneath the link, you’ll see example code of how this works in Easy FancyBox.

    • #4791
      Richard Barnhart
      Participant

      I also saw an older post that had some code you could put in the footer that would disable the plugin for mobile devices. I tried it and it disabled the plugin for all devices including desktops, but again, it was an older post. Do you have new code like that I could use in the footer that works?

    • #4792
      RavanH
      Keymaster

      This code in a text widget should do the trick:

      
      <script type="text/javascript">
      var pixelRatio = window.devicePixelRatio || 1;
      //alert('Screen size: ' + window.innerWidth + ' / ' + pixelRatio + ' = ' + window.innerWidth/pixelRatio);
      if( window.innerWidth/pixelRatio < 420 ) {
        //alert('Fancybox disabled.');
        easy_fancybox_handler = null;
      };
      </script>
      

      For testing purposes, remove the // in front of the alert(...) lines. It will create a message stating calculated screen width and a message if FancyBox is disabled on smaller devices. Remove those alert lines after testing.

      EDIT: Oh, and change the value 420 to disable FancyBox starting from another screen size.

    • #4793
      Richard Barnhart
      Participant

      Thanks. Will this work in the footer too? I have a large site and don’t want to put a text widget on every page.

    • #4798
      RavanH
      Keymaster

      Yes, in the themes footer.php is fine, as long as you place the snippet BEFORE/ABOVE the <?php wp_footer(); ?> call. When placed after it, the snippet will have no effect.

      But please be aware that theme updates will overwrite your changes, unless you’re using a custom theme. If you’re not using a custom theme, then you might want to create a child theme to prevent footer.php from being overwritten in the future.

    • #4846
      Richard Barnhart
      Participant

      Thanks, this is working great, except it turns of the fancy box for all files, not just pdf. Is there a way to make this script work for pdf files only? I still want my videos to work on iPad. Thanks.

    • #4851
      Pharéo
      Keymaster

      Hi Richard,

      Try replacing the line

      
      easy_fancybox_handler = null;
      

      in the code snippet with

      
      jQuery('a[href*=".pdf"], area[href*=".pdf"]').addClass('nofancybox');
      
Viewing 7 reply threads
  • You must be logged in to reply to this topic.