# アクションボタンからのレコード作成時のみ、ウインドウを閉じる

**URL:** <https://community.cybozu.dev/t/topic/5999>\
**Category:** kintone 開発相談\
**Created:** [May 18, 2022, 5:19am UTC](https://community.cybozu.dev/t/topic/5999 "2022-05-18T05:19:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account1796](https://avatars.discourse-cdn.com/v4/letter/l/13edae/32.png) [@Legacy\_Account1796](https://community.cybozu.dev/u/Legacy_Account1796)\
**Post date:** [May 18, 2022, 5:19am UTC](https://community.cybozu.dev/t/topic/5999/1 "2022-05-18T05:19:05Z")

</div>

表題通りですが、アクションボタンで別アプリのフォーム入力画面を新しく開いた際に保存ボタンを押したとき、新しく開いたほうのウインドウを自動的に閉じるJavascriptをつくっていますが、うまくいきません。

仕組みとしては元アプリと別アプリ両方にアクションボタンからレコードを作成した際用のフラグフィールドを用意してそこからチェックしてフラグが有効な際はウインドウを閉じる仕組みにしています。(チェック終了後にフラグは戻す)

以下ソースです(フラグのフィールド名がaction)

※コードブロックがうまく貼り付けられないため、そのままコードを書いてます

(function() {  
&nbsp; &nbsp; “use strict”;  
&nbsp; &nbsp; var flag;  
&nbsp; &nbsp; kintone.events.on(‘app.record.edit.show’, function(event) { //保存前  
&nbsp; &nbsp; &nbsp; &nbsp; var rec = event.record;  
&nbsp; &nbsp; &nbsp; &nbsp; var obj = event.get(“record”);  
&nbsp; &nbsp; &nbsp; &nbsp; var act = obj.get(“action”);

&nbsp; &nbsp; &nbsp; &nbsp; flag = act.get(“value”);  
&nbsp; &nbsp; &nbsp; &nbsp; if(flag == “1”){ //アクションフラグが立ってる場合  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rec[‘action’].value = “0” ; //フラグを戻す  
&nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; return event;  
&nbsp; &nbsp; });

&nbsp; &nbsp; kintone.events.on([‘app.record.create.submit.success’, ‘app.record.edit.submit.success’], function(){ //保存成功後  
&nbsp; &nbsp; &nbsp; &nbsp; if(flag == “1”){ //アクションフラグが立ってる場合  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.open(‘about:blank’, ‘\_self’).close(); //ウインドウを閉じる  
&nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; });  
&nbsp; })();

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1517](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@Legacy\_Account1517](https://community.cybozu.dev/u/Legacy_Account1517)\
**Post date:** [May 18, 2022, 11:45am UTC](https://community.cybozu.dev/t/topic/5999/2 "2022-05-18T11:45:52Z")

</div>

kintone が開いたウインドウは、kintone しか閉じることができないようです。

[window.close](https://developer.mozilla.org/ja/docs/Web/API/Window/close) より

\>このメソッドが許可されるのは、window.open() メソッドを用いたスクリプトにより開かれたウィンドウに対する呼び出しのみです。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1796](https://avatars.discourse-cdn.com/v4/letter/l/13edae/32.png) [@Legacy\_Account1796](https://community.cybozu.dev/u/Legacy_Account1796)\
**Post date:** [May 18, 2022, 11:42pm UTC](https://community.cybozu.dev/t/topic/5999/3 "2022-05-18T23:42:39Z")

</div>

コメントありがとうございます。

kintoneではできないということですね。了解しました。
