Note that there are some explanatory texts on larger screens.

plurals
  1. PODownload a file in hidden iframe: Android equivalent in Comet context?
    primarykey
    data
    text
    <p>I am currently using the following JS code to trigger a file download without leaving the page I'm on:</p> <pre><code>var iframe = document.createElement('iframe'); iframe.style.display = 'none'; document.body.appendChild(iframe); iframe.src = "/somefile.zip"; </code></pre> <p>It works well pretty much everywhere I tested except on both the stock Android browser and Dolphin, where the download doesn't start at all. So far so good, after some research this hidden iframe trick happens to be known not to work on the Android browser.</p> <p>But I tried several other methods to trigger the download on the Android browser, including <code>window.open()</code> (not reliable because popup blocking is enabled by default), or <code>&lt;a target="_blank"&gt;</code> with a simulated <code>click()</code> (which from a popup blocker perspective amounts to <code>window.open()</code> and gets blocked), or <code>document.location = ...</code> which downloads the file but breaks my app.</p> <p>The problem with the latter <code>document.location = ...</code> is that this is a Comet application (server-push / long polling) so I really can't leave the page I'm currently on (and "leaving" includes changing <code>document.location</code> even for a file download, <strong>even if <em>apparently</em> the browser stays on the current page</strong>) otherwise the long polling connection is stopped and the updates stop, the app breaks. This obviously also applies when clicking normal links, either manually or simulated.</p> <p>So in order not to break my app I really need to trigger a file download <strong>without</strong> leaving the page I'm on. Unfortunately I didn't find any viable solution that also works on the stock Android browser.</p> <p>Any ideas?</p> <p>Thanks for reading me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload