JS调用浏览器自带下载功能下载图片

			function download(src) {
			    var $a = document.createElement('a');
			    $a.setAttribute("href", src);
			    $a.setAttribute("download", "");


			    var evObj = document.createEvent('MouseEvents');
			    evObj.initMouseEvent( 'click', true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);
			    $a.dispatchEvent(evObj);
			};

src为图片地址,src='http://localhost:8080/aaa/bbb/ccc/20170517111819.png';

你可能感兴趣的:(JavaScript)