我有一个docs插件,我需要通过调用onOpen(e)函数中的警报来向用户显示其新的更新和功能。重要的是,一生只有一次
OR
就像不再显示按钮一样。
我该怎么做?
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('ez-notes', 'Sidebar')
.addToUi();
DocumentApp.getUi().alert("new feature..."); //will trouble user everytime.
}
答案 0 :(得分:2)
有一个名为onInstall()
它用于附加组件。它仅在安装附加组件时运行。
function onInstall() {}
每当发布新版本的加载项时,都不会运行。如果您希望某些代码仅针对新发布的版本运行一次,那么您将需要存储用户在某处使用的当前版本和最后一个版本,然后在运行某些代码时对它们进行比较。您可以在“属性服务”,“脚本属性”或硬编码当前版本号中保存版本号应该是什么。每次oOpen()函数运行时,您都需要运行一些服务器代码,将当前版本与用户使用的上一个已知保存版本进行比较。
我有一个功能,除了返回当前最新版本应该做什么之外什么都不做,每当新版本发布时我都会更改该数字:
function newestVersion() {return "12";}// Return the newest version number
function onOpen() {
var newestVersion,lastUsedVersion;
newestVersion = newestVersion();//Call function to get the newest version
lastUsedVersion = fncGetLastUsedVersion();//Run function to get last used version
if (lastUsedVersion !== newestVersion) {
//Display message
//Save new value of Last Used Version to User or Document Properties
}
}
function lastUsedVersion() {
//Get last used version from User or Document Properties
}
答案 1 :(得分:1)
这是一种方法,这可能比Sandy的版本更复杂 - 但我在过去的脚本中使用它:
var ss = SpreadsheetApp.getActiveSpreadsheet();
function onOpen() {
var documentProperties = PropertiesService.getDocumentProperties();
Utilities.sleep(100)
var checkOpen = documentProperties.getProperty('checkOpenStatus');
Utilities.sleep(100)
if(checkOpen == "true") {
}
else {
newfeature();
}
};
function newfeature() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle('New feature');
var panel = app.createVerticalPanel();
// add the html panel
app.add(app.createHTML("<b>New features</b><br><br><b>1.</b>New feature text"));
// adds checkbox
var cBox = app.createCheckBox("Do Not show this on Load").setName("chk1").setId("chk1");
// set check box stuff
var cBoxClick = app.createServerClickHandler('checked');
cBoxClick.addCallbackElement(cBox);
cBox.addClickHandler(cBoxClick);
app.add(cBox);
app.add(panel);
doc.show(app);
return app;
}
function checked(e) {
var app = UiApp.getActiveApplication();
if (e.parameter.chk1 == "true")
{
var documentProperties = PropertiesService.getDocumentProperties();
Utilities.sleep(100)
documentProperties.setProperty('checkOpenStatus', 'true');
}
else
{
var documentProperties = PropertiesService.getDocumentProperties();
Utilities.sleep(100)
documentProperties.setProperty('checkOpenStatus', 'false');
}
return app;
}
&#13;