简体   繁体   English

Mobile Safari-HTML下载链接打开标签页,而不是下载文件

[英]Mobile Safari - Html download link opens tab instead of downloading file

I'm working with a webapp that has a link to download an xml file. 我正在使用一个Web应用程序,该应用程序具有下载xml文件的链接。 As in, click the link, browser downloads the file. 如图所示,单击链接,浏览器下载文件。 The file downloads as expected from Chrome/FF/Safari on my desktop. 该文件将按预期从我的桌面上的Chrome / FF / Safari下载。 It also works from FF when I spoof my User Agent to be an iPad. 当我将用户代理欺骗为iPad时,它也可以从FF使用。 But when clicked from Mobile Safari on an iPad, the link navigates the browser to a new page and tries to display the xml as html, without downloading anything. 但是,当从iPad上的Mobile Safari单击时,该链接会将浏览器导航到新页面,并尝试将xml显示为html,而不下载任何内容。

Currently the HTTP Response contains the following headers: 当前,HTTP响应包含以下标头:

Content-Disposition:attachment; filename="myFile.xml"    
Content-Type:application/octet-stream;charset=UTF-8

It's my understanding that these two HTTP headers should tell the browser to download, rather then display, the response stream. 据我了解,这两个HTTP标头应该告诉浏览器下载而不是显示响应流。

Does someone know why this doesn't work in Mobile Safari, running on an iPad? 有人知道为什么这在iPad上运行的Mobile Safari中不起作用吗?

MobileSafari will usually not download files, even if instructed to in an HTTP header. 即使在HTTP标头中指示,MobileSafari通常也不会下载文件。 For example, it's impossible to download an MP3 from a website in MobileSafari, it's just going to play it. 例如,不可能从MobileSafari网站上下载MP3,而只是要播放它。 This stems from the iPhones/iPads not having a user-accessable file system - if you can't access the file system, there's really no way to save or access downloaded files. 这源于iPhone / iPad没有用户可访问的文件系统-如果您无法访问文件系统,则实际上无法保存或访问下载的文件。 So, because MobileSafari can't download files, it's just going to try and display it, no matter what the HTTP header says. 因此,由于MobileSafari无法下载文件,所以无论HTTP标头说什么,它都将尝试显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 下载链接打开链接而不是下载它 - The download link opens the link instead of downloading it 如何在网页上添加机制以将 html 文件下载到他们的移动设备? (链接打开页面而不是下载 html 文件) - How can I add a mechanism on a web page to download an html file to their mobile device? (The link opens page rather than downloading the html file) 下载属性打开文件而不是下载 - Download attribute opens file instead of downloading html 'download' 属性打开一个新页面而不是下载 - html 'download' attribute opens up a new page instead of downloading 带有下载属性的锚标签打开文件而不是下载 - Anchor tag with download attribute opens file instead of downloading 文件打开而不是在href链接中的Internet Explorer中下载 - File opens instead of downloading in internet explorer in a href link 在新标签页中打开html文件,而不是下载它 - Open html file in a new tab instead of downloading it HTML-在浏览器中打开指向文件的链接,而不是下载 - Html - Open a link to a file in browser instead of download 创建的下载链接打开链接而不是下载它 - the created download link to open the link instead of downloading it 为什么此<a href download>HTML 重定向到文件而不是下载?</a> - Why Does This <a href download> HTML Redirect to File Instead of Downloading?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM