如何下载一个XML没有浏览器的另一个选项卡中打开它 [英] How to download an XML without the browser opening it in another tab

查看:97
本文介绍了如何下载一个XML没有浏览器的另一个选项卡中打开它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须下载一个XML文件。
大家都知道,当我给下面的链接

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>

XML将打开一个新的标签显示它。
不过,我想知道是否有一种方法,这可以像其他下载的文件,如.zip文件

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

帮助将不胜AP preciated

Help would be greatly appreciated

感谢

推荐答案

有一个HTTP头被称为内容处置,这是在的 RFC1806 如下:

There's an HTTP header called Content-Disposition, which is defined in RFC1806 as follows:

一个正文部分应标在线如果打算要
  在显示器自动显示
  消息的。内联正文部分应在订单psented $ P $
  它们发生,受
  多部分消息的正常语义。

2.1 The Inline Disposition Type

A bodypart should be marked inline if it is intended to be displayed automatically upon display of the message. Inline bodyparts should be presented in the order in which they occur, subject to the normal semantics of multipart messages.

正文部分可以指定
   附件以表明它们是
  从的主体分开
  邮件,他们的显示不应该是自动的,但
  在一些进一步的行动队伍
  用户的。该MUA可能代替
  present一个位图的用户
  终端有一个标志性的重presentation
  的附件,或者,上
  字符终端,以列表
  附件从该用户
  可以选择收看或储存。

Bodyparts can be designated attachment to indicate that they are separate from the main body of the mail message, and that their display should not be automatic, but contingent upon some further action of the user. The MUA might instead present the user of a bitmap terminal with an iconic representation of the attachments, or, on character terminals, with a list of attachments from which the user could select for viewing or storage.

为了把头消息的XML文件,你需要访问到服务器端。例如使用PHP的功能,您可以写这样的:

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:

header('Content-Disposition: attachment; filename="some.xml"');

如果您没有访问服务器端,你可以试试下面的JavaScript把戏,我发现谷歌搜索(不知道是否会工作):

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):

<a href="javascript:void(0);" onclick="document.execCommand('SaveAs',true,'some.xml');">Save this page</a> 

这篇关于如何下载一个XML没有浏览器的另一个选项卡中打开它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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