Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3886

Provide an alternative download feature for mobile iOS devices

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Won't Do
    • Icon: Normal Normal
    • 8.5.2
    • 8.5.1
    • None
    • Security Level: Jimmy
    • None
    • mobile iOS devices (iPad, iPhone), safari, firefox, chrome

    • ZK 8.5.2 S1

      Note: most problem happen on chrome for iOS (ipad), other environment may or may not display the issue
      The current Filedownload.save() API in ZK cannot be used in iOS devices due to the following issues:

      • iOS browsers blocks events able to trigger a download generated outside of a direct user action (user touch on link, etc.), therefore, no such download can be started in a callback such as received from zkau
      • If the browser cannot read the file format (such as zip, rar, etc.), iOS browsers don't start downloading automatically. instead, they display a "document ready for download" page showing details of the document, and let the user "open the document" in one of their applications (such as google drive, dropbox, etc). Since ZK filedownload.save() triggers download by opening the url of the document in a hidden iframe, the iframe will show the "document read for download" page, but the user will not see it.

      Those two behaviors cause file access to be impossible in iOS under the current Filedownload feature.

      Possible improvement:
      Providing an alternative behavior for iOS mobile device under which a popup is displayed, showing a direct link to the file. The user would then be able to access the URL and download the file.

      Rough POC illustrating the idea below
      Note : this code only supports static files with a public URL. If a file is not public, or if it is generated on the fly without a static url, the following will not work.

      <script><![CDATA[
       zk.afterLoad('zk', function() {
        zAu.cmd0.download =function (url) {
        if (url) {
         if (zk.mobile && zk.safari) {
          zk.load("zul.wnd, zul.utl", function () {
              var myWin= new zul.wnd.Window({
                  children: [new zul.wgt.A({href:url,target:"_blank",label:"click here to download"})]
             });
             zk.$('@page').appendChild(myWin);
             myWin.setBorder("normal");
             myWin.setClosable(true);
             myWin.setTitle("Download");
             myWin.doModal();
          });
         }else if(zk.ios){
          var link = document.createElement('a'),
            evt = document.createEvent('Event');
           link.id = 'zk_download';
           link.href = url;
           if (!(zk.ios >= 7)) //ZK-2245: it's restriction to programmatically open new tab since ios7
            link.target = '_blank';
           evt.initEvent('click', true, false);
           link.dispatchEvent(evt);
         }else{
          var ifr = jq('#zk_download')[0];
          if (ifr) {
           ifr.src = url; //It is OK to reuse the same iframe
          } else {
           var html = '<iframe src="' + url
           + '" id="zk_download" name="zk_download" style="display:none;width:0;height:0;border:0" frameborder="0"></iframe>';
           jq(document.body).append(html);
         }
         }
        }
       }
       });//zk.afterLoad
       ]]></script>
      

            klyvechen klyvechen
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 4 hours
                4h
                Remaining:
                Time Spent - 1 hour Remaining Estimate - 3 hours
                3h
                Logged:
                Time Spent - 1 hour Remaining Estimate - 3 hours
                1h