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: 等于 - ...
随机推荐
- hook笔记②
- What is the difference between Serialization and Marshaling?
How to serialize and deserialize JSON using C# - .NET | Microsoft Docs https://docs.microsoft.com/en ...
- python RecursionError: maximum recursion depth exceeded while calling
import copyimport sys # 导入sys模块sys.setrecursionlimit(8192) # 将默认的递归深度修改为r = sys.getrecursionlimit()_ ...
- (002)每日SQL学习:删除名称重复的数据
create table A ( id VARCHAR2(36), name VARCHAR2(100), sl VARCHAR2(36) ); insert all into a (id,name) ...
- TCP/IP中的Payload概念以及由此引申出的一些问题
TCP报文一次性最大运输的货物量(Payload),大体可以这么来计算: IP报文头长度 + TCP报文头长度 + Payload长度 ≤ MTU 即左边的三者之和,要小于等于右边MTU的长 ...
- Page (computer memory) Memory segmentation Page table 虚拟地址到物理地址的转换
A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described ...
- Axure RP 9版本最新版授权码和密钥 亲测可用
分享Axure RP 9版本最新版授权码和密钥 亲测可用 声明:以下资源的获取来源为网络收集,仅供学习参考,不作商业用途,如有侵权请联系博主删除,谢谢! 自新的Axure RP 9.0 Beta版发布 ...
- python实现文件查找功能,excel写入功能
因为要丛UE文档中过滤关键字来统计解码时间,第一次自己完成了一个自动化统计的小工具,用起来颇有成就感. UE文件的内如如下: 需要丛这份关键字中过滤红色标记的两个关键字,取 一个关键字的最后一位,和取 ...
- Spring Cloud Config、Apollo、Nacos配置中心选型及对比
Spring Cloud Config.Apollo.Nacos配置中心选型及对比 1.Nacos 1.1 Nacos主要提供以下四大功能 2.Spring Cloud Config 3.Apollo ...
- 调用个别f5 负载端口为80的vs时,返回值为空的问题
现状: vs负载端口为80并添加XFF,pool包含2个member,member的monitor端口为80&9000. 故障现象: 应用同事描述说再完全复制了一个member并添加到pool ...