Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Ignores Content-Disposition: Attachment Inside Iframe
    primarykey
    data
    text
    <p>I have a link to a download handler inside an iframe. This download handler has "Content-Disposition: Attachment" in the headers to force the user to download the file. This works in every browser <em>except</em> on Android devices. Android ignores the file without any errors or messages. Using Fiddler, i can confirm that the handler is getting requested successfully, &amp; the download appears to complete successfully, but the browser is not letting me save or open the file.</p> <p>Before you tell me to stop using iframes, i am afraid that is not an option for me at this time.</p> <p>Below is some code to reproduce this issue. Three files:</p> <ol> <li>Default.aspx: Contains an iframe pointing to DownloadPage.aspx</li> <li>DownloadPage.aspx: Contains a hyperpink to Download.ashx</li> <li>Download.ashx: Responds with a text/plain content-type type with content-disposition: attachment</li> </ol> <p>Default.aspx:</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AndroidTest.Default" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;iframe src="DownloadPage.aspx" width="320" height="1000"&gt;&lt;/iframe&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>DownloadPage.aspx</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DownloadPage.aspx.cs" Inherits="AndroidTest.DownloadPage" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:HyperLink NavigateUrl="~/Download.ashx" runat="server"&gt;Download&lt;/asp:HyperLink&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Download.ashx.cs</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace AndroidTest { /// &lt;summary&gt; /// Summary description for Download /// &lt;/summary&gt; public class Download : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.AddHeader("Content-Disposition", "attachment;filename=\"test.txt\""); context.Response.Write("Hello World"); } public bool IsReusable { get { return false; } } } } </code></pre> <p>Thanks for your time.</p>
    singulars
    1. This table or related slice is empty.
    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