我正在嘗試在 GAS 中開發一個腳本,以便在運行谷歌表格中的腳本之前顯示加載對話框。代碼如下
function dispStatus(title, html, width, height) {
// Display a modeless dialog box with custom HtmlService content.
var title = typeof (title) !== 'undefined' ? title : 'No Title Provided';
var width = typeof (width) !== 'undefined' ? width : 180;
var height = typeof (height) !== 'undefined' ? height : 180;
var html = typeof (html) !== 'undefined' ? html : '<p>No html provided.</p>';
var htmlOutput = HtmlService
.createHtmlOutput(html)
.setWidth(width)
.setHeight(height);
SpreadsheetApp.getUi().showModelessDialog(htmlOutput, title);
}
然后我們在運行腳本前后呼叫這個函式
function Hello() {
dispStatus('Loading...', '<img src=https://media.giphy.com/media/{id}/giphy.gif width="120" height="110">', 120, 120)
//some code
dispStatus('Done!', '<img src=https://media.giphy.com/media/{id}/giphy.gif width="120" height="80"><script>var myVar = setInterval(myTimer ,1000);function myTimer() { google.script.host.close();}</script>', 120, 120)
}
獲取加載對話框并在腳本結束后關閉它的整個操作運行良好。但是當對話框打開時,用戶仍然可以在后臺編輯作業表,我想避免這種情況。我在這里想要實作的是,當顯示加載對話框時,用戶無法編輯任何內容。我已經對此進行了研究,并且有一種方法可以通過 HTML 來實作。但是我自己無法解決這個問題,因為我是在 GAS 中使用 Html 的新手。任何幫助都非常有用
例如

參考:
- 在谷歌腳本中的側邊欄和模態對話框之間進行通信
uj5u.com熱心網友回復:
雖然我不確定我是否能正確理解你的目標,但為了實作你的目標,使用showModalDialog而不是showModelessDialog如下如何?
從:
SpreadsheetApp.getUi().showModelessDialog(htmlOutput, title);
至:
SpreadsheetApp.getUi().showModalDialog(htmlOutput, title);
參考:
showModelessDialog(用戶界面,標題)
showModalDialog(用戶界面,標題)
模態對話框阻止用戶與對話框以外的任何東西進行互動。相比之下,無模式對話框和側邊欄讓用戶與編輯器進行互動。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/494448.html
