HTML5 download 执行条件
HTML5 download 执行条件
同一个域名下的资源
http only
绝对路径/相对路径 都可以
demo
https://cdn.xgqfrms.xyz/HTML5/auto-dwonload-images/index.html
跨域的第三方资源,会直接跳转到第三方资源连接
file:///Users/xgqfrms-mbp/Documents/GitHub/cdn/html5/download/image-auto-downloader.html 不好使,会直接打开连接

<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="author" content="xgqfrms">
<meta name="generator" content="VS code">
<title>image auto downloader</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
</style>
<!-- <link rel="stylesheet" href="./index.css"> -->
</head>
<body>
<header>
<h1>image auto downloader</h1>
</header>
<main>
<!-- -->
<a href="https://cdn.xgqfrms.xyz/logo/icon.png" download="">https://cdn.xgqfrms.xyz/logo/icon.png</a>
<a href="../../../logo/icon.png" download="">../../../logo/icon.png</a>
<!-- http only??? -->
<a href="https://dn-simplecloud.shiyanlou.com/1487741005890.png" download >image auto downloader</a>
<a href="https://dn-simplecloud.shiyanlou.com/1487741005890.png" download="" style="visibility: hidden;">image auto downloader</a>
<a href="https://dn-simplecloud.shiyanlou.com/1487741005890.png" download="" style="display: none;">image auto downloader</a>
<div>
<a href="https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows" download="shortcuts-zh.pdf">download pdf</a>
<a href="https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf" download="shortcuts-zh.pdf">download pdf</a>
</div>
</main>
<footer>
<p>copyright© xgqfrms 2020</p>
</footer>
<!-- js -->
<script>
const log = console.log;
</script>
</body>
</html>
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-10-01
* @modified
*
* @description image auto downloader
* @difficulty Easy Medium Hard
* @complexity O(n)
* @augments
* @example
* @link
* @solutions
*
* @best_solutions
*
*/
const log = console.log;
let divs = [...document.querySelectorAll(`.learn-path-item`)];
for (let i = 0; i < divs.length; i++) {
const div = divs[i];
const img = div.firstElementChild;
// log(`img src =`, img.src);
// window.open(img.src);
autoDownloader(img.src, 1000);
}
const autoDownloader = (url = ``, timer = 0) => {
const body = document.querySelector(`body`);
const a = document.createElement(`a`);
// only read property
// a.src = url;
//
a.setAttribute(`href`, url);
// a.setAttribute(`src`, url);
// VM17:9 Uncaught TypeError: Failed to execute 'setAttribute' on 'Element': 2 arguments required, but only 1 present.
// a.setAttribute(`download`);
a.setAttribute(`download`, true);
// a.setAttribute(`download`, ``);
// a.setAttribute(`style`, `display:none;`);
// a.setAttribute(`style`, `visibility: hidden;`);
body.insertAdjacentElement(`beforeend`, a);
// body.insertAdjacentHTML(``);
// a.addEventListener(`click`, (e) => {
// e.preventDefault();
// });
a.click();
// a.click();
setTimeout(() => {
// DOM remove
body.removeChild(a);
// a.remove();
// delete a;
}, timer);
}
// Downloader(`https://dn-simplecloud.shiyanlou.com/1487741005890.png`, 1000)
/*
const divs = [...document.querySelectorAll(`a`)];
for (let i = 0; i < divs.length; i++) {
const div = divs[i];
autoDownloader(div.href, 1000);
}
*/
same origin
download only works for same-origin URLs, or the blob: and data: schemes.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download

https://caniuse.com/?search=download

https://stackoverflow.com/questions/49760160/a-download-attribute-not-working-anymore
blob
var funDownload = function (content, filename) {
// 创建隐藏的可下载链接
var eleLink = document.createElement('a');
eleLink.download = filename;
eleLink.style.display = 'none';
// 字符内容转变成blob地址
var blob = new Blob([content]);
eleLink.href = URL.createObjectURL(blob);
// 触发点击
document.body.appendChild(eleLink);
eleLink.click();
// 然后移除
document.body.removeChild(eleLink);
};
https://www.zhangxinxu.com/wordpress/2017/07/js-text-string-download-as-html-json-file/
https://www.zhangxinxu.com/wordpress/2016/04/know-about-html-download-attribute/
refs
https://github.com/xgqfrms/HTML5/issues/11#issuecomment-706642998
test
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
HTML5 download 执行条件的更多相关文章
- html5 download all in one
html5 download all in one HTML5 download & Fetch API & File API & Blob https://scarletsk ...
- html5 download blob
html5 download blob https://stackoverflow.com/questions/19327749/javascript-blob-filename-without-li ...
- DEVOPS技术实践_23:判断文件下载成功作为执行条件
在实际生产中,我们经常会需要通过判断一个结果作为一个条件去执行另一个内容,比如判断一个文件是否存在,判官一个命令是否执行成功等等 现在我们选择其中一个场景进行实验,当某个目录下存在,则执行操作 1. ...
- 利用CodeDom 动态执行条件表达式
在实际需求遇到需要根据不同条件,去指定不同的不同的审批人.起初的需求倒很简单,明确是当金额 >=500000 , 可变的就是500000这个数额. 当时为了防止可能产生的变化.特意搞了 条 ...
- rander()函数执行条件
调用this.setState({}),如果数据改变了,rander()就行执行
- 公用表表达式(CTE)引发的改变执行顺序同WHERE条件顺序引发的bug
以下模拟一下CTE出错 /*测试环境 Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) Apr 2 2010 15:48:46 Copyr ...
- ARM指令集——条件执行、内存操作指令、跳转指令
ARM 汇编指令条件执行 在ARM模式下,任何一条数据处理指令可以选择是否根据操作的结果来更新CPSR寄存器中的ALU状态标志位.在数据处理指令中使用S后缀来实现该功能. 不要在CMP,CMN,TST ...
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
- Bash条件判断
bash编程之:条件判断,判定后续操作的前提条件是否满足, bash编程之: 条件判断常用类型: 整数测试:比较两个整数谁大谁小,是否相等: 二元测试: num1 操作符 num2 -eq: 等于 - ...
随机推荐
- python 使用函数名的字符串调用函数(4种方法)_black-heart的专栏-CSDN博客 https://blog.csdn.net/mrqingyu/article/details/84403924
funcs = ['fetch_data_' + i for i in ( 'activities', 'banners', 'server_list')]# from operator import ...
- Cannot assign requested address问题总结
Cannot assign requested address问题总结 - 简书 https://www.jianshu.com/p/51a953b789a4 python3 server.pyE07 ...
- Mysql四种通信协议(linux下本地连接的都是socket 其他都是tcp)
Mysql通信协议 - 张冲andy - 博客园 https://www.cnblogs.com/andy6/p/6204579.html
- 那些我们不知道的 Python 免费学习资料
作者:小R编辑:AI 兔兔 Python 语言因为其易学,以及强大的功能,是很多刚开始学习编程的入门语言的选择之一. Python 语言被列入中小学教材后引起了越来越多人的关注. 希望孩子学习编程的家 ...
- python 基础二-----数据类型和控制语句
一.数据类型: 1)数据类型 1.整数(int) 2.浮点数(float) 3.字符串(string) 4.列表(list) 5. 元组(tuple) 6.字典(dict): key和value是一一 ...
- Windows操作Redis及Redis命令
Windows操作Redis及Redis命令 一.Windows下操作Redis 设置密码 打开redis服务 Windows 下的redis命令行 二.redis常用命令大全 key String ...
- Kubernetes --(k8s)yml 文件
认识yml文件 yaml文件语法 大小写敏感 使用缩进表示层级关系 缩进时不允许使用Tab键,只允许使用空格. 缩进的空格数目不重要,只要相同层级的元素左侧对齐即可 # 表示注释,从这个字符一直到行尾 ...
- jvm学习第一天
视频教程链接 第一部分-jvm初识 0.jvm概览图 JVM由三个主要的子系统构成 类加载子系统 运行时数据区(内存结构) 执行引擎运行时数据区(内存结构) 1.什么是jvm 定义: ①. JVM 是 ...
- Unity3d开发中遇到的问题记录
安装Unity unity官方提供免费的community版本,功能健全,下载时还有Visual Studio,非常方便. 官方文档 Unity的官方文档非常权威!详尽!可靠!很多关于函数细节的疑惑都 ...
- jQuery读取数据
1.jQuery读取JSON <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...