如何从Google Apps脚本HTML文件中关闭弹出窗口?

时间:2015-10-21 14:12:13

标签: html google-apps-script

我无法关闭弹出窗口。我正在使用此表单:https://script.google.com/macros/s/AKfycbzcQLIRAeESGM4Y23s2tRSv4QNLcrUspF3cn5Lqo8bZP22znp8/exec

在此内部,有两个文件:server.gs文件代码:

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('form.html');
}

function uploadFiles(form) {

try {

var d = new Date();
          var month = d.getMonth()+1;
          var day = d.getDate();
          var hour = d.getHours();
          var minute = d.getMinutes();
          var second = d.getSeconds();
          var datums = ((''+day).length<2 ? '0' : '') + day + '.' + 
          ((''+month).length<2 ? '0' : '') + month + '.' + d.getFullYear();

          var laiks = ((''+hour).length<2 ? '0' :'') + hour + ':' +
          ((''+minute).length<2 ? '0' :'') + minute; 

var folder, folders = DriveApp.getFoldersByName(datums);

if (folders.hasNext()) {
  folder = folders.next();
} else {
  folder = DriveApp.createFolder(datums);
}

var blob1 = form.myFile1;    
var file1 = folder.createFolder(form.myName);
var filename = file1.createFile(blob1);
filename.setDescription("Uploaded by " + form.myName);

var blob2 = form.myFile2;
var filename = file1.createFile(blob2);
filename.setDescription("Uploaded by " + form.myName);

var blob3 = form.myFile3;
var filename = file1.createFile(blob3);
filename.setDescription("Uploaded by " + form.myName);

var blob4 = form.myFile4;
var filename = file1.createFile(blob4);
filename.setDescription("Uploaded by " + form.myName);

return "Faili veiksmīgi pārsūtīti. Varat aizvērt šo logu.";
// Added

} catch (error) {

return error.toString();
}

}

function close() {
var app = UiApp.getActiveApplication();
app.close();
// The following line is REQUIRED for the widget to actually close.
return app;
}

这是HTML文件form.html代码:

<form id="myForm">
<table>
  <tbody>
    <tr>
      <td><label>Ievadiet Jūsu vārdu</label></td>
      <td><input type="text" name="myName" placeholder="Jūsu vārds..."></td>
    </tr>
    <tr>
      <td><label>Tehniskās apliecības kopija</label></td>
      <td><input type="file" name="myFile1"></td>
    </tr>
    <tr>
      <td><label>Vadītāja apliecības kopija</label></td>
      <td><input type="file" name="myFile2"></td>
    </tr>
    <tr>
      <td><label>Saskaņotā paziņojuma kopija</label></td>
      <td><input type="file" name="myFile3"></td>
    </tr>
    <tr>
      <td><label>Cits dokuments</label></td>
      <td><input type="file" name="myFile4"></td>
    </tr>
  </tbody>
</table>

    <input type="submit" value="Upload File" 
           onclick="this.value='Uploading..';
                    google.script.run.withSuccessHandler(fileUploaded)
                    .uploadFiles(this.parentNode);
                    return false;">
</form>
<div id="output"></div>

<input type="button" value="Close" onclick="window.close()" />

<script>
    function fileUploaded(status) {
        document.getElementById('myForm').style.display = 'none';
        document.getElementById('output').innerHTML = status;
    }
</script>

<style>
 input { display:block; margin: 20px; }
</style>

唯一不起作用的是我的“关闭”按钮。 :(

我想要做的是 - 关闭此窗口。此窗口将显示为弹出窗口。

1 个答案:

答案 0 :(得分:0)

使用Class google.script.host

<input type="button" value="Close" onclick="google.script.host.close()" />