0
0

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.

ポップアップウィンドウを閉じたときに親ウィンドウの関数を呼ぶ (IE,Edge両対応)

Last updated at Posted at 2021-02-04

Edgeの場合

  • onbeforeunload

もしくは

  • onunload
function popup(url) {
	if (! window.showModalDialog) {
		// IE以外 (Edgeなど)
		modalWin = window.open(url);
	} else {
		// IE
		modalWin = window.showModalDialog(url);
	}
	return modalWin;
}

//-----------------

var url = "https://qiita.com";
if (modalWin = popup(url)) {
	if (! window.showModalDialog) {
		// IE以外 (Edgeなど)
		modalWin.onunload = function () {
			alert("onunload");
		}
		modalWin.onbeforeunload = function () {
			alert("onbeforeunload");
		}
	} else {
		// IE
		alert("IE");
	}
}
addEventListenerの例
function unloaded() {
	location.reload();
}

var modalWin = window.open(url);                 
if (! window.showModalDialog) {
	// IE以外
	modalWin.addEventListener('beforeunload', unloaded, false);
} else {
	// IE
}

showModalDialog の代替

window.showModalDialog がない場合は以下を用いるとよいかも。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?