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

烂漫一生 提交于 2019-12-12 22:47:27

问题


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.

Currently the HTTP Response contains the following headers:

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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/10490558/mobile-safari-html-download-link-opens-tab-instead-of-downloading-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!