アプリ版:「スタンプのみでお礼する」機能のリリースについて

子windowsからsubmit()後にclose()を実行するとsubmit()が起動しないが発生
①function ok()でclose();を実行すると、submit();が実行されない、子windowはcloseされる
②function ok()でclose();をコメント化、submit();が実行されるが、子windowはcloseされない
③期待値は submit();が実行され、子windowはcloseされる
 下記の3ファイルからなるアプリケーションにおいての
 具体的な解決方法をお知らせください

//--HTML文 ファイル名(GZ.htm)----------------------------------------
<html><body>
<meta http-equiv=Content-Type content='text/html; charset=Shift_JIS; '>
<script src=GZ.js></script>
<form name=myform action='GZ.cgi' method='post'>
<input type=hidden name=Htm value='HTM'>
<center>
<a onClick=CmdBox()><!--フォーム送信時CmdBox関数を定義する-->
<img src='img.jpg' height=150><br>
img.jpg
</a>
</form></body></html>
//--script文 ファイル名(GZ.js)---------------------------------------
function ok(){alert("ok(0:");
// close(); //コメントアウトしないとsubmit()が起動されなう
document.all("myform").submit();
}
function can(){alert("can(0:");
close(); //自身windowのクローズ(正常動作)
}
function CmdBox(){//コマンドボックスを表示する
Dialog_win=window.open( '表示','Dialog_win','width='+50+',height='+50+',left='+50+',top='+250);
Dialog_win.document.write('<html><body>'
+"<"+"script src=GZ.js><"+"/script>"
+"<meta http-equiv=Content-Type content='text/html; charset=Shift_JIS;'>"
+"<form name=myform action=GZ.cgi method=post>"
+"<input type=hidden name=Htm value='HTM'>"
+"<center>コマンドボックス<br><br>"
+"<input onClick='ok();' type=button value=回転>"
+"<input onClick='can();' type=button value=キャンセル>"
+'</form></body></html>'
);
}
//--perlによるCGI文 ファイル名(GZ.cgi)------------------------------
#!/usr/local/sbin/perl
use Cwd;
#use Win32;Win32::MsgBox("GZ.cgi=".cwd());
read(STDIN,$read_STDIN,$ENV{'CONTENT_LENGTH'});
open STDERR," >","GZ.log";
print STDERR "GZ.cgi:cwd()=".cwd()."\n\$read_STDIN=\n$read_STDIN\n";
#$read_STDINの内容による個々の処理、画像回転等
$l=1;print STDOUT $STDOUTstr="<!DOCTYPE html>\n"
."<html>\n"
."<head>\n"
."<meta http-equiv='Content-Type' content='text/html; charset=Shift_JIS;'>\n"
."<meta http-equiv='refresh'content='0;url=GZ.htm'>\n"
."</head>\n"
."</html>\n";
close STDOUT;
print STDERR $STDOUTstr;
close STDERR;

質問者からの補足コメント

  • 子windowでOK、キャンセルの選択のケースをお願いします

    No.1の回答に寄せられた補足コメントです。 補足日時:2022/03/10 01:06
  • HAPPY

    解決で大変ありがとうございました。

      補足日時:2022/03/11 10:52

A 回答 (3件)

No2です。



何度もすみません、以下の方が、今後何か変えたくなったとき多少見通しが良いかもしれません。


//--script文 ファイル名(GZ.js)---------------------------------------
function CmdBox(){//コマンドボックスを表示する

// 子windowを開く
Dialog_win=window.open( '','Dialog_win','width=50,height=50,left=50,top=250');

// 子windowに表示するものは3つ。テキスト、okボタン、cancelボタン
const frag = document.createDocumentFragment(),
box_text = Object.assign(document.createElement('p'), {
style:'text-align:center;',
textContent: 'コマンドボックス'
}),
ok_btn = Object.assign(document.createElement('input'), {
type:'button',
value:'回転'
}),
cancel_btn = Object.assign(document.createElement('input'), {
type: 'button',
value: 'キャンセル'
});

// テキストと、ok,cancelボタンを子windowに格納する
frag.appendChild(box_text);
frag.appendChild(ok_btn);
frag.appendChild(cancel_btn);
Dialog_win.document.body.appendChild(frag);

// ok,cancelボタンがクリックされたとき
Dialog_win.addEventListener('click',(e)=>{
if(e.target === ok_btn){
Dialog_win.alert('OK');
document.forms.myform.submit(); // 親windowからform送信
Dialog_win.close();
}else if(e.target === cancel_btn){
Dialog_win.alert('cancel');
Dialog_win.close();
}
},false);
}

いずれにせよ、
・フォーム送信は親windowがする、
・クローズ命令は子windowにする、
というところだけがポイントです。
    • good
    • 1

>子windowでOK、キャンセルの選択のケースをお願いします



こんな感じでしょうか。

//--script文 ファイル名(GZ.js)---------------------------------------
function CmdBox(){//コマンドボックスを表示する
Dialog_win=window.open( '表示','Dialog_win','width=50,height=50,left=50,top=250');
Dialog_win.document.write(`<html><head>
<meta http-equiv=Content-Type content='text/html; charset=Shift_JIS;'>
<script>
function ok(){
alert("ok(0:");
if(window.opener){ // 親windowの確認
window.opener.document.forms.myform.submit(); // 親windowからフォーム送信
close(); // 子windowのクローズ
}else{ // 親windowがなかった時
document.body.textContent = 'ブラウザ非対応か、もしくは親windowがありません';
}
}
function can(){alert("can(0:");
close();
}</script></head>
<body>
<p>コマンドボックス</p>
<input onClick='ok();' type=button value=回転>
<input onClick='can();' type=button value=キャンセル>
</body></html>`);
}

参考:
https://developer.mozilla.org/ja/docs/Web/API/Wi …
    • good
    • 0

window.openではなく、confirmを使うのはいかがでしょうか。



//--script文 ファイル名(GZ.js)---------------------------------------
function CmdBox(){//コマンドボックスを表示する
if(window.confirm('回転しますか')){
document.forms.myform.submit();
}
}
この回答への補足あり
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています