js 图片保存至手机相册

	var triggerEvent = "touchstart";  //指定下载方式
	function savePicture(Url) {
		var blob = new Blob([''], { type: 'application/octet-stream' });
		var url = URL.createObjectURL(blob);
		var a = document.createElement('a');
		a.href = Url;
		a.download = Url.replace(/(.*\/)*([^.]+.*)/ig, "$2").split("?")[0];
		var e = document.createEvent('MouseEvents');
		e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
		a.dispatchEvent(e);
		URL.revokeObjectURL(url);
	}
savePicture(Url); 
// Url 为图片的服务器地址  http://****.com/cwap/images/userqrcode/06144477550415791.pngfinal.png

你可能感兴趣的:(js 图片保存至手机相册)