How to force links to open in iOS Safari?

☆樱花仙子☆ 提交于 2019-11-30 05:28:55

问题


my webpage has links to download Passbook .pkpass files. This works fine in Safari for iOS since Apple's browser supports the mime type: application.com/vnd.apple.pkpass

Facebook's iOS browser (as well as others) does not (yet) support this mime type. Therefore, if a user follows a link to my site from within Facebook, they can't download my Passbook files. However, if they click on 'Open in Safari' then they can download the file.

How can I code my webpage such that clicking on a link will force open Safari on iOS?

Andrew


回答1:


These headers should be helpful to what you're doing.

Content-Type "application/force-download"
Content-Description "File Transfer"
Content-Disposition attachment
ForceType "application/octet-stream"

I suggest you try to set them in your .htaccess or httpd.conf file with the following code:

<FilesMatch "\.(pkpass)$">
Header set Content-Type "application/force-download"
Header set Content-Description "File Transfer"
Header set Content-Disposition attachment
Header set ForceType "application/octet-stream"
</FilesMatch>

It's a little overkill, but will ensure the download is forced across all browsers. Change the pkpass to anything else to force the download of any other file type.




回答2:


I didn't manage to find a way to do this yet. Somehow, forced pkpass downloads won't work in the Facebook mobile browser.

The best way is to guide the user to open the page in Safari.



来源:https://stackoverflow.com/questions/14537235/how-to-force-links-to-open-in-ios-safari

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