0

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

4

1 回答 1

0

如此处所述

“这只有在应用程序显示为对话框时才有效,例如在 Google 电子表格中。在作为独立服务发布的应用程序上调用时,它不会产生任何影响。”

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

于 2012-11-08T19:17:46.530 回答