JS笔记-让chrome跳过「允许下载多个档案」的技巧

目录

JS笔记-帮元素加上style的写法
JS笔记-getPosition 让你找到元素x,y位置
js笔记--写脚本需要用到的waitForKeyElements.js
JS笔记-设定CSSstyle的function
JS笔记-使用fetch下载档案/download.js好用的东西
JS笔记-前端新手练习小专案(附加4个JS实例网站可学)
JS笔记-关掉alert的简单小技巧
JS笔记-使用ajax传送表单(ex.传送google表单)
JS笔记-前端拨放m3u8的两种方法
JS笔记-让chrome跳过「允许下载多个档案」的技巧
JS笔记-製作copy效果
JS笔记-暂时让网页可以编辑
JS笔记-VScode自己设定速打
JS笔记-VScode的Prettier(自动排版)怎么开始使用?

前情提要

常常写JS下载一堆东西,但user还要自己手动点选:「允许下载多个档案」

能下载时候热血沸腾,但是,要点这家伙就让人乾掉了。
因此今天的笔记就是能够使用JS跳过此步骤。

var webview = null;function isSafeUrl(url) {  // You may want to perform a more rigorous check.  // There's a technique that creates an <a> to parse the URI, but that seems  // like a security risk.  return !!url.match(/^(?:ftp|https?):\/\//i);}function onPermissionRequest(event) {  switch (event.permission) {    case 'download':      if (isSafeUrl(event.request.url)) {        event.request.allow();      } else {        event.request.deny();      }      break;    // You can add code for other permissions here.  }}function onDomReady() {  webview = document.getElementById('webview');  webview.addEventListener('permissionrequest', onPermissionRequest);}document.addEventListener('DOMContentLoaded', onDomReady);

笔记来源:
https://stackoverflow.com/questions/20479956/how-to-allow-downloads-inside-webview-in-google-chrome-app


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章