英文:
How can I put django static files in javascript array?
问题
var links = [
'/static/uploads/fth/FthAgg.xlsx',
'/static/uploads/fth/FthCon.xlsx'
];
{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="{% static 'css/pages/fthpage.css' %}">
<script src="{% static 'js/downloads.js' %}"></script>
<title></title>
</head>
<body>
<h1 class="header_h1">FTH Page</h1>
<button onclick="downloadAll(window.links)">Test me!</button>
</body>
</html>
This wont work though. When I try to put https links it will work.
Here is my javascript file: https://pastebin.com/0sCTav8G
Here is my html template: https://pastebin.com/yvz2AL0M
英文:
I need to get static files from django to a "links" array...
var links = [
'/static/uploads/fth/FthAgg.xlsx',
'/static/uploads/fth/FthCon.xlsx'
];
This is the html:
{% load static %}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="{% static 'css/pages/fthpage.css' %}">
<script src="{% static 'js/downloads.js' %}"></script>
<title></title>
</head>
<body>
<h1 class="header_h1">FTH Page</h1>
<button onclick="downloadAll(window.links)">Test me!</button>
</a>
</body>
</html>
This wont work though. When I try to put https links it will work.
Im doing this so that i can later download these files simultaniously with one button.
Here is my javascript file:
https://pastebin.com/0sCTav8G
Here is my html template:
https://pastebin.com/yvz2AL0M
答案1
得分: 0
function downloadAll(links)
{
for (i = 0, len = links.length; i < len; i++) {
var link = links[i];
var a = document.createElement("a");
var file = 'file' + i + '.xlsx';
a.setAttribute('href', 'data:text/plain;charset=utf-8, ' + link);
a.setAttribute('download', file);
a.click();
}
}
英文:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
function downloadAll(links)
{
for (i = 0, len = links.length; i < len; i++) {
var link = links[i];
var a = document.createElement("a");
var file = 'file'+ i + '.xlsx';
a.setAttribute('href', 'data:text/plain;charset=utf-8, '
+ link);
a.setAttribute('download', file);
a.click();
}
}
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论