移动Safari - Html下载链接打开选项卡,而不是下载文件 [英] Mobile Safari - Html download link opens tab instead of downloading file

查看:177
本文介绍了移动Safari - Html下载链接打开选项卡,而不是下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个有下载xml文件链接的web应用程序。如在,点击链接,浏览器下载文件。该文件在我的桌面上按照预期从Chrome / FF / Safari下载。当我欺骗我的用户代理成为iPad时,它也可以从FF工作。但是,当从iPad上的Mobile Safari中点击时,链接会将浏览器导航到新页面,并尝试将xml显示为html,而无需下载任何内容。

I'm working with a webapp that has a link to download an xml file. As in, click the link, browser downloads the file. The file downloads as expected from Chrome/FF/Safari on my desktop. It also works from FF when I spoof my User Agent to be an iPad. 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.

目前HTTP响应包含以下标题:

Currently the HTTP Response contains the following headers:

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

这是我的理解,这两个HTTP头应该告诉浏览器下载,而不是显示响应流。

It's my understanding that these two HTTP headers should tell the browser to download, rather then display, the response stream.

有人知道为什么这样做'在移动Safari中工作,在iPad上运行?

Does someone know why this doesn't work in Mobile Safari, running on an iPad?

推荐答案

MobileSafari通常不会下载文件,即使指示在HTTP头。例如,从MobileSafari网站下载MP3是不可能的,它只是要播放它。这源于iPhones / iPad没有用户可访问的文件系统 - 如果您无法访问文件系统,则真的没有办法保存或访问下载的文件。因此,由于MobileSafari无法下载文件,因此无论HTTP标头如何显示,它都会尝试显示它。

MobileSafari will usually not download files, even if instructed to in an HTTP header. For example, it's impossible to download an MP3 from a website in MobileSafari, it's just going to play it. 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. So, because MobileSafari can't download files, it's just going to try and display it, no matter what the HTTP header says.

这篇关于移动Safari - Html下载链接打开选项卡,而不是下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆