js H5 视频地址 转 视频下载功能 打开的正确方式....

	function downVideo (url, name){
		var xhr = new XMLHttpRequest();
		xhr.open('GET', url, true);
		xhr.responseType = 'blob';    // 返回类型blob
		xhr.onload = function () {
			 if (xhr.readyState === 4 && xhr.status === 200) {
				  let blob = this.response;
				  // 转换一个blob链接
				  let u = window.URL.createObjectURL(new Blob([blob]))
				  let a = document.createElement('a');
				  a.download = name;
				  a.href = u;
				  a.style.display = 'none'
				  document.body.appendChild(a)
				  a.click();
				  a.remove();
			 }
		};
		xhr.send()
	}

 

你可能感兴趣的:(js,视频地址转下载功能,h5)