我想创建类似的东西"href=filename.txt". The "filename"文本文件的属性及其内容需要根据单击的标签动态创建。
我使用 Web API 获取 JSON 格式的数据,因此相信安全性不应该成为问题。
As of HTML5,您可以组合使用data: URL http://www.w3.org/TR/html51/single-page.html#data-protocol and download属性 http://www.w3.org/TR/html51/single-page.html#downloading-resources。例如,
$("a#programatically").click(function() {
var now = new Date().toString();
this.href = "data:text/plain;charset=UTF-8," + encodeURIComponent(now);
});
在这里查看。 http://jsfiddle.net/enbMe/
很遗憾,download属性不完全支持 http://caniuse.com/#feat=download and data:网址进展顺利 http://caniuse.com/#feat=datauri.