0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【GAS】msgBox()で表示されるポップアップにおけるボタンの扱い方

Posted at

概要

GASではBrowser.msgBox()でポップアップ(ダイアログ)を表示できます。

このとき、Yes, No, Cancelのボタンを表示することができ、押されたボタンで処理を分岐させることができます。

ボタンが押されるまで処理は一時停止しており、ボタン押下で次の処理へ行きます。

実装

基本形(OKボタンのみ)

ユーザにメッセージを通知したいだけで、回答を求めていない場合。

Browser.msgBox("ポップアップです。OKボタンのみ表示されます。");

OK, Cancelボタン

OK, Cancelボタンが必要な場合は、第2引数に"Browser.Buttons.OK_CANCEL"を入れる。
戻り値で回答が分かる。

var res = Browser.msgBox("Message", Browser.Buttons.OK_CANCEL);
if(res == "ok"){
  //OKボタンが押された際の動作
}else if(res == "cancel"){
  //Cancelボタンが押された際の動作
}

以降第2引数が違うだけであとは同じ要領です。

Yes, Noボタン

var res = Browser.msgBox("Title", "Message", Browser.Buttons.YES_NO);
if(res == "yes"){
  //yesボタンが押された時の動作
}else if(res == "no"){
  //noボタンが押された時の動作
}

Yes, No, Cancel

var res = Browser.msgBox("Message", Browser.Buttons.YES_NO_CANCEL);
if(res == "yes"){
  //yesボタンが押された時の動作
}else if(res == "no"){
  //noボタンが押された時の動作
}else if(res == "cancel"){
  //Cancelボタンが押された際の動作
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?