"下载"属性< a>标签不适用于IE,Safari或Opera [英] "download" attribute on <a> tag doesn't work on IE, safari or Opera

查看:150
本文介绍了"下载"属性< a>标签不适用于IE,Safari或Opera的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有标准的方法来制作类似的东西?我只想要一种从服务器下载xml文件的方法。请帮助我!

are there any standard way to make something similar?? I just want a way to download xml files from the server. Please help me!

推荐答案

不,据我所知,使用HTML无法做到这一点。

No, as to my knowledge there is no way to do this using HTML.

您必须在目标页面上修复它。如果发送了某个HTTP标头,浏览器将提供一个下载页面而不是显示它。这应该适用于所有主流浏览器。必要的标题是 Content-Type:octet-stream 。如何发送这取决于您的设置。

You have to fix it on the target page. If a certain HTTP header is sent, the browser will offer a page for download instead of displaying it. This should work in every major browser. The necessary header is Content-Type: octet-stream. How you send this depends on your setup.

您可以随时通过配置您的Web服务器来发送它,但是如何取决于您正在使用的Web服务器。

You can always send it by configuring your web server to do so, but how exacly depends on which web server you are using.

另一方面,如果您的XML文件是由PHP脚本生成的,那么很容易。只需在编写其他内容之前添加以下行 ,因此最好在所述脚本的顶部添加:

If, on the other hand, your XML file is generated by a PHP script, it's easy. Just add the following line before anything else is written, so preferably to the top of said script:

header('Content-Type: application/octet-stream');

如果它是一个静态XML文件......好吧,你可以为它创建一个代理文件 。添加包含以下内容的PHP文件:

If it's a static XML file... well, you could make a "proxy file" for that. Add a PHP file with the following content:

<?php
header('Content-Type: application/octet-stream');
// This "fakes" the file name, so the downloaded file isn't called
// "download_xml_file.php" or whatever you name the script.
header('Content-Disposition: attachment; filename=my_xml_file.xml');
readfile('path_to_the_actual_xml_file.xml');
?>

但要尽量避免这种黑客行为。这是不必要的膨胀,它将破坏浏览器缓存。

But try to avoid this hack. It's unnecessary bloat and it will break browser caching.

这篇关于&QUOT;下载&QUOT;属性&lt; a&gt;标签不适用于IE,Safari或Opera的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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