任何干净的方式来下载像html5下载属性的文件 [英] any clean ways to download files like html5 download attribute

查看:101
本文介绍了任何干净的方式来下载像html5下载属性的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全清楚在javascript / jQuery中下载文件方面有很多争论(和解决方案),例如 iFrame jQueryPlugin 。但是,我对HTML5中的下载属性< a> 等内置设施更感兴趣。问题是它支持,它支持所有现代浏览器。

  var blob = new Blob([Hello,world!],{type:text / plain; charset = utf-8}); 
saveAs(blob,hello world.txt);


I am fully aware that there are many debates(and solutions) out there in terms of downloading files in javascript/jQuery, such as iFrame, jQueryPlugin. However, I am more interested in a kind of built-in facilities like download attribute of <a> in HTML5. The problem is that it supports a couple of browsers:

That is how I want to download files, without creating frames or using any plugins. The questions is are there any other cross browser built-in(say, easier or cleaner) ways to do it?

  • Internet Explorer 8+
  • Firefox 19+
  • Chrome 17+
  • Safari 5.1.9+
  • Opera 12.1

解决方案

You might want to try FileSaver.js which has support for all modern browsers.

var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");

这篇关于任何干净的方式来下载像html5下载属性的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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