![](/img/trans.png)
[英]How do I move an html dialog window? (Google spreadsheet apps script dialog)
[英]HTML Dialog don't close in a shared spreadsheet on Google Scripts
我有一個電子表格,它有一個 function 來調用一個 HTML 對話框來選擇一些日期:
htmlDate = HtmlService.createHtmlOutputFromFile('datePicker')
.setHeight(120)
.setWidth(550);
SpreadsheetApp.getUi().showModalDialog(htmlDate, 'Select the dates for presentation:');
這是 HTML 代碼的一部分,它定義了 datePicker.html 中按鈕的操作:
<input type="button" onClick="submitForm()" value="OK" />
<input type="button" onClick=google.script.host.close() value="Cancel" />
這是 HTML 代碼的一部分,它調用我的 function 'newPresentation':
<script type="text/javascript">
function submitForm() {
google.script.run.newPresentation(document.forms[0]);
Utilities.sleep(1000);
google.script.host.close();
}
</script>
問題是:當我運行腳本時,它運行良好。 首先,它調用我的 function 'newPresentation',然后它自行關閉,運行腳本的 rest。 在 function 'newPresentation' 中,還有其他 HTML 對話框被調用。
但是,當另一個用戶運行腳本時,此 HTML 對話框不會自行關閉。 即使它沒有自行關閉,腳本的 rest 也會正常執行。 我已經與另一個具有編輯權限的用戶共享了電子表格。 我和其他用戶都登錄了 Google 帳戶。
一些想法如何解決這個問題?
PS.:對不起,有些語法錯誤,但我英語不流利。
嘗試這個:
google.script.run
.withSuccessHandler(function(){google.script.host.close();})
.newPresentation(document.forms[0]);
並在 newPresentation() 的末尾添加一個 return;
另一種可能性是嘗試使用此處描述的虛擬對話框: https://stackoverflow.com/a/55731456/7215091
我不確定問題發生的原因。 在我進行的所有測試中,我使用了同一台計算機,兩台 windows 谷歌瀏覽器(每個登錄用戶一台)。 我無法解決問題。
之后,我在一台新計算機上進行了測試,只有一個用戶登錄,腳本運行良好。
顯然,可能是與瀏覽器中的某些緩存有關的一些問題,或者其他什么。 我真的不知道。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.