简体   繁体   English

从Javascript返回具有Content-type的文件内容

[英]Return file contents with Content-type from Javascript

I'm trying to include a vCard in a Weebly website, but I need to return the Content-type header, so a simple attachment won't work. 我正在尝试在Weebly网站中包括vCard,但我需要返回Content-type标头,因此无法使用简单的附件。 I have found the following code in PHP to do this, but I can't include PHP code on Weebly, only Javascript: 我已经在PHP中找到以下代码来执行此操作,但是我无法在Weebly上仅包含Javascript来包含PHP代码:

<?php
    header("Content-type: text/x-vcard");
    header("Content-Disposition: attachment; filename=\"contact.vcf\";");
    echo file_get_contents("contact.vcf");
?>

Is there a way to include a button that would return this in Javascript? 有没有办法包含一个可以在Javascript中返回此按钮的按钮?

您应该能够将其添加到简单的锚标记中,然后浏览器将对其进行处理。

<a href="contact.vcf">My Contact</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM