【发布时间】:2021-10-01 05:36:58
【问题描述】:
我是谷歌脚本的新手,目前我有一个模式对话框,可以在下图中打开一个 html 文件。
我希望能够按下打开仪表板按钮并关闭此框并打开另一个模式对话框,但是我很难弄清楚如何。与普通 html 不同,由于某种原因,我不能使用 href 来引用我的其他 html 文件。我也尝试过关闭模式框,然后调用打开初始对话框的 GS 函数,但是传入新的 html,也无济于事。我假设我在这里遗漏了一些简单的东西,因为这通常是微不足道的,但我不确定我遗漏了什么,任何建议将不胜感激。
代码.gs
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Jigs & Tools')
.addItem('First item', 'displayHtmlViewer')
.addToUi();
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
function displayHtmlViewer(file = "index"){
var html = HtmlService.createTemplateFromFile(file)
.evaluate()
SpreadsheetApp.getUi().showModalDialog(html, 'J&T Dashboard');
}
索引.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<?!=include('stylesheet');?>
</head>
<body style="background-color:powderblue;">
<div class="btnGroup2" style="width:100%">
<button style="width:50%" button onclick="google.script.host.close() ; google.script.run.displayHtmlViewer('dashboard')">Open dashboard</button>
</div>
<div class="divider"/></div>
<div class="btnGroup1" style="width:100%">
<button style="width:50%">Future Button 1</button>
<button style="width:50%">Future Button 2</button>
</div>
<div class="divider"/> </div>
<div class="btnGroup1" style="width:100%">
<button style="width:50%">Future Button 3</button>
<button style="width:50%">Future Button 4</button>
</div>
<div class="divider"/> </div>
<div class="btnGroup1" style="width:100%">
<button style="width:50%">Future Button 5</button>
<button style="width:50%">Future Button 6</button>
</div>
<div class="divider"/> </div>
<div class="btnGroup2" style="width:100%" id=myBtn>
<button style="width:50%" button onclick="google.script.host.close()"> Exit </button>
</div>
</body>
</html>
dashboard.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h4>This is the Dashboard</h4>
</body>
</html>
【问题讨论】:
标签: html google-apps-script google-sheets