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

File download doesn't work with Chrome in iOS

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Won't Fix
    • Affects Version/s: 8.0.2
    • Fix Version/s: None
    • Component/s: None
    • Security Level: Jimmy
    • Labels:
    • gh.sprint.customfield.default.name:
      ZK 8.0.3 S4

      Description

      steps to reproduce

      1. open chrome to simulate iPad with dev tool
      2. run the code below:
        <zk>
        <button label="Download " onClick="download()">
        </button>
        <zscript><![CDATA[
                import org.apache.poi.util.*;
                public void download() throws java.io.IOException{
                	org.zkoss.zul.Filedownload.save(IOUtils.toByteArray(support.issue.IssueVM.class.getResourceAsStream("test.pdf")), "application/pdf", "test.pdf");
                }
        ]]>
        </zscript>
        </zk>
        
      3. click the button to download a file

      result

      root cause

      f (zk.mobile) {
      	zAu.cmd0.download = function (url) {
      		if (url) {
      			var link = document.createElement('a'),
      				evt = document.createEvent('Event');
      			link.id = 'zk_download';
      			link.href = url;
      			if (!(zk.ios >= 7)) 
      				link.target = '_blank';
      			evt.initEvent('click', true, false);
      			link.dispatchEvent(evt);
      		}
      	};
      }
      

      firing a click event on an anchor element will trigger onbeforeunload event, so client engine sends remove desktop au. Then the target resource becomes unavailable.

      debug info

      • this issue doesn't happen in 7.x
      • a user reported chrome and safari on iPad2 (iOS 9.2.1) also has this issue. (But I cannot reproduce this with physical iPad)
      • He said if he visits the link generated by the AU response e.g. http://localhost:8080/zk8support/zkau/view/z_t59/dwnmed-0/ck7/test.pdf, he gets a 410 HTTP error on both iOS and Android. (But I cannot reproduce this issue)
      • Android phones don't have such issue in the example above.

      workaround

      <script defer="true"><![CDATA[
      zAu.cmd0.download = function (url) {
       if (url) {
        var ifr = jq('#zk_download')[0];
        if (ifr) {
         ifr.src = url; 
        } 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);
        }
       }
      };
      ]]>
      </script>
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              SEFI SEFI
              Reporter:
              hawk hawk
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: