Troubleshooting website display or functionality issues in Edge on Windows 10
このブラウザーはサポートされなくなりました。
Microsoft Edge にアップグレードすると、最新の機能、セキュリティ更新プログラム、およびテクニカル サポートを利用できます。
JavascriptのWindow.close()を使用した場合タブが閉じない現象が発生します。
具体的には
1. 新規タブをjavascriptで開く
2. 更新ボタンなど別のJavasciptを使用したボタンを使用する
3. 「閉じる」ボタン(window.close()を使用)を押してもタブが閉じない。
なお、2を飛ばした場合はちゃんとタブは閉じられます。
3でボタンを押下した場合、コンソール上では"Scripts may close only the windows that were opened by them."と出ます。
発生OS : Windows 10
発生ブラウザ: Edge (V 87.0.664.66)
なお、Chromeでも同様の現象が発生します。
Internet Explorerでは「閉じますか」とポップアップが出たのちにタブを閉じることができます。
Troubleshooting website display or functionality issues in Edge on Windows 10
ロックされた質問。 この質問は、Microsoft サポート コミュニティから移行されました。 役に立つかどうかに投票することはできますが、コメントの追加、質問への返信やフォローはできません。
新しいウィンドウで開いたときは、どうなのか。
新しいタブで開いた場合でも新しいウィンドウで開いた場合でも、同じ現象が発生します。
実装(インプリメント)に関しては、先ほどの返信では不十分だと感じたので、以下のように実装しました。
> 2. 更新ボタンなど別のJavasciptを使用したボタンを使用する
2はUploadボタンを押した場合を指しています(以下の実装のUploadボタンは動作していませんが、実際には正しくサーバーに転送されるよう実装しています)。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Portal</title>
<script>
// Set action
$(function() {
$("#upload\_button").on("click", sendFile);
$("#close").on("click", function(){window.close();});
});
</script></head><body>
<div class="header">
<table class="header">
<tbody><tr>
<td class="title"><h1>Portal</h1></td>
</tr>
</tbody></table>
</div>
<div class="contents\_full">
<table id="overview\_send\_file" class="detail">
<tbody><tr>
<th>File</th>
<td>
<input type="file" id="upload\_file" name="upload\_file"><br>
<div id="send\_error\_message" class="error"></div>
</td>
<td class="research">
<button id="upload\_button">Upload</button>
</td>
</tr>
</tbody></table>
<form id="overview\_reload" name="overview\_reload" method="post" action="./overview.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="overview\_reload" value="overview\_reload">
<div class="operationButtom"><input id="overview\_reload:uuid" type="hidden" name="overview\_reload:uuid"><input id="overview\_reload:recieve\_flag" type="hidden" name="overview\_reload:recieve\_flag" value="true"><input id="overview\_reload:file\_name" type="hidden"
name="overview\_reload:file\_name"><input id="overview\_reload:file\_size" type="hidden" name="overview\_reload:file\_size"><input id="overview\_reload:reload\_button" type="submit" name="overview\_reload:reload\_button" value="Reload" disabled="">
<button type="button" id="close" onclick="window.opener = 'opener';window.close()">Close</button>
</div><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="1574452699217922328:-8847575202580103027" autocomplete="off">
</form>
</div>
</body></html>
© ウィンドウズスクリプトプログラマ - Windows Script Programmer 2020
1. 新規タブをjavascriptで開く
新しいウィンドウで開いたときは、どうなのか。
いずれにせよ、こちらでは、closeできたり、できなかったり、まるで再現性がない。インプリメントがデタラメなんじゃないか。デタラメなものは使えない。
© ウィンドウズスクリプトプログラマ - Windows Script Programmer 2020
そういう流れみたい。逆らっても仕様がない。完全に詰められてる。
Javascript部分は以下のように実装しました
$(function() {
$("#upload\_button").on("click", sendFile);
$("#close").on("click", function(){window.close();});
});
HTML側では以下のように実装しました。
<button type="button" id="close" onclick="window.opener = 'opener';window.close()">閉じる</button>
以上です。
© ウィンドウズスクリプトプログラマ - Windows Script Programmer 2020
最小再現ソースを提示。