我的google应用脚本html页面上有URL链接列表。我有一个下载按钮。当我点击下载按钮时,我想使用URL链接从我的谷歌驱动器下载所有文件到我的电脑。
首先: 我尝试将一个链接放在我的google驱动器上的文件夹中。但它不起作用。
我在公共域中共享了电子表格文件https://docs.google.com/spreadsheets/d/1sXWWAdfEIJSj9_QPBjkR6CKhd4bzrYIMa4hImipySWI/edit?usp=sharing
网络链接:https://script.google.com/macros/s/AKfycbwkBfuZzSDV5UgQLugJoWXH-2pDrtqsd2Ph5HAkx_oFOvR6gD0/exec 请搜索名称“sam”
你能帮帮我吗?谢谢。
//启动html部分
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p>Enter the name: sam </p>
<div>
<form id="searchform">
<input name="nameperson" type="text">
<input type="submit" value="search">
</form>
</div>
<div id="result">
</div>
<div id="download" hidden="true">
<button> download </button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#searchform").submit(function(){
google.script.run.withSuccessHandler(function(valreturn){
var response=JSON.parse(valreturn);
var newHTML=[];
newHTML.push('<table>' + '<tr>' +'<th>'+"Name"+'</th>'+
'<th>'+"URL"+'</th>'+ '<tr>');
for( var i=response.length-1; i >= 0 ; i--){
newHTML.push('<tr>' + '<td>' + response[i].name + '</td>' +
'<td>' + '<a href= " ' + response[i].url + ' " target="_blank" >' + "url" + '</a>' + '</td>' + '</tr>');
}
$("#result").html(newHTML.join(""));
$("#download").show();
}).seachRecord(this);
});
$("#download").click(function() {
alert("how can I download these files ?");
});
});
function preventFormSubmit() {
var forms = document.querySelectorAll('form');
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener('submit', function(event) {
event.preventDefault();
});
}
}
window.addEventListener('load', preventFormSubmit);
</script>
</body>
</html>
//结束HTML
function getFilepdf() {
var fileURL="https://drive.google.com/file/d/0BybO_Qe9EIRKZExPSWJJXzl1ajQ/view";
var response = UrlFetchApp.fetch(fileURL);
var fileBlob = response.getBlob();
fileuploadpdf(fileBlob);
}
function fileuploadpdf(filedata){
try {
var dropbox = "stackflowfolder";
var folder, folders = DriveApp.getFoldersByName(dropbox);
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(dropbox);
}
var blob = filedata;
var file = folder.createFile(blob);
} catch (error) {
return error.toString(); }
}