简体   繁体   中英

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. 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM