如何下载 XML,而无需浏览器在另一个选项卡中打开它
我有一个 xml 文件需要下载。 众所周知,当我提供以下链接时,
<a href="some.xml">Downlad XML</a>
XML 将在显示它的新选项卡中打开。 但是我想知道是否有办法可以像其他文件(例如 .zip 文件)一样下载它
I have an xml file to be downloaded.
As you all know when i give the below link
<a href="some.xml">Downlad XML</a>
The XML will open in a new tab displaying it.
However I would like to know if there is a way, this can downloaded like other files such as a .zip file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在尝试了很多解决方案之后,这对我有用。
尝试为文件链接提供一个虚拟参数,如下所示。
After trying a lot of solutions, This worked for me.
Try to provide a dummy argument to the file link as shown below.
有一个名为 Content-Disposition 的 HTTP 标头,它在 RFC1806 中定义如下:
为了将标头消息放在 xml 文件中,您需要访问服务器端。例如,使用 php 的 header 函数,您可以编写如下内容:
如果您不这样做可以访问服务器端,你可以尝试以下我在谷歌上找到的 JavaScript 技巧(不确定它是否有效):
There's an HTTP header called Content-Disposition, which is defined in RFC1806 as follows:
In order to put the header message on the xml file, you'd need the access to the server-side. For example using php's header function you could write something like:
If you don't have access to the server-side, you could try the following JavaScript trick that I found Googling (not sure if it would work):
我发现只需右键单击网络浏览器并选择“将页面另存为...”即可完成工作。
I found that just right clicking on the web browser and selecting "Save Page As..." does the work.
与上面 Mohd 的解决方案类似,我可以使用 W3 指定的下载属性: http:// /www.w3schools.com/tags/att_a_download.asp。走这条路线的一个很酷的技巧是,如果下载的文件名与服务器上的文件名不同,您可以指定您想要的文件名。
Similar to Mohd's solution above, I was able to use the download attribute as specified by W3 here: http://www.w3schools.com/tags/att_a_download.asp. A cool trick about going this route is that you can specify what you want the downloaded filename to be, if it is different from the filename on the server.
使用类似的东西:
use something like:
这是我的 VBA 解决方案。宏将下载 XML 文件,将其保存在宏文件的文件夹中,并在该过程完成后通知用户:
Here is my VBA solution. The macro will download the XML file, save it in macro file's folder and inform the user once the process has been completed:
只需在锚标记中添加“下载”属性即可
Just add the 'download' attribute in the anchor tag