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

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

问题描述

我有一个xml文件被下载。
众所周知,当我提供以下链接

 < a href =some.xml> Downlad XML< / a> 

XML将在显示它的新选项卡中打开。
但是我想知道是否有一种方式,这可以像其他文件一样下载,如.zip文件



帮助将不胜感激, p>

谢谢

解决方案

有一个名为Content-Disposition的HTTP头在 RFC1806 中定义如下:



< blockquote>

2.1内联处理类型



一个bodypart应该被标记为 inline 如果打算在
显示消息时自动显示
。在线bodyparts应以
的顺序显示,它们出现,取决于
多部分消息的正常语义。



2.2附件处理类型



Bodyparts可以指定
附件表示他们是
与主分开
邮件的正文,并且他们的显示不应该是自动的,而
取决于用户的进一步操作
。 MUA可能代替
向用户提供位图
终端,附加符号为
,或者在
字符终端上列出
附件用户
可以从中选择查看或存储。


为了将标题消息放在xml文件上,您需要访问服务器端。例如,使用php的标题功能,您可以编写以下内容:

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

如果您无法访问服务器端,可以尝试以下JavaScript技巧我发现谷歌(不知道是否可以使用):

 < a href =javascript:void(0); onclick =document.execCommand('SaveAs',true,'some.xml');>保存此页面< / a> 


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

Help would be greatly appreciated

Thanks

解决方案

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

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.

2.2 The Attachment Disposition Type

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.

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"');

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天全站免登陆