为什么close()什么都不做?

时间:2012-11-08 19:10:06

标签: google-apps-script

app.close()没有做任何事情吗?它似乎不起作用.... // Script-as-app模板。 示例代码

function doGet() {
  var app = UiApp.createApplication();

  var button = app.createButton('Click Me');
  var closeButton = app.createButton('Close It');
  app.add(closeButton);
  app.add(button);

  var label = app.createLabel('The button was clicked.')
                 .setId('statusLabel')
                 .setVisible(false);

  var label2 = app.createLabel('The Close button was clicked.')
                 .setId('statusLabel2')
                 .setVisible(false);
  app.add(label);
  app.add(label2);
  var closeHandler = app.createServerHandler('close');
  closeHandler.addCallbackElement(label);
  var handler = app.createServerHandler('myClickHandler');
  handler.addCallbackElement(label);
  closeButton.addClickHandler(closeHandler);
  button.addClickHandler(handler);

  return app;
}

function myClickHandler(e) {
  var app = UiApp.getActiveApplication();

  var label = app.getElementById('statusLabel');
  label.setVisible(true);

  app.close();
  return app;
}
function close(e)
{
  Logger.log("Here");
  var app = UiApp.getActiveApplication();
  var label2 = app.getElementById('statusLabel2');
  label2.setVisible(true);
  return app.close();
}

链接到示例代码 https://script.google.com/a/macros/scotts.com/s/AKfycbz-avIT3bZNJ68_EpRZYXmh66XLJzYI--F0n7DGNn8jL_wlG1k/exec

1 个答案:

答案 0 :(得分:0)

记录在案here

  

“这仅在应用程序显示为对话框时才有效,例如在   Google电子表格。在app上调用时无效   作为独立服务发布。“

顺便说一句,这是浏览器的一个基本限制 - 页面无法自行关闭。