Skip to content

Instantly share code, notes, and snippets.

@programus
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save programus/197e699e4024c6536005 to your computer and use it in GitHub Desktop.
Save programus/197e699e4024c6536005 to your computer and use it in GitHub Desktop.
close popup after changed html
<!DOCTYPE html>
<html lang="ja-JP">
<head>
<title>From</title>
<meta charset="UTF-8">
</head>
<body onload="document.getElementById('closed-flg').checked = true;">
<input type="checkbox" id="closed-flg"/>
<a href="#" onclick="window.open('popup.html', 'popup'); document.getElementById('closed-flg').checked = false; ">popup</a>
<a href="#" id="link-to" onclick="window.location.href='to.html' + (document.getElementById('closed-flg') ? '' : '?popup');">To</a>
</body>
</html>
<!DOCTYPE html>
<html lang="ja-JP">
<head>
<title>Pop Up</title>
<meta charset="UTF-8" />
<script>
var notifyClose = function() {
window.opener.document.getElementById('closed-flg').checked = true;
};
window.onbeforeunload = notifyClose;
</script>
</head>
<body onunload="notifyClose();" >
Popup Page
</body>
</html>
<!DOCTYPE html>
<html lang="ja-JP">
<head>
<title>To</title>
<meta charset="UTF-8" />
<script>
var closeWindow = function () {
var s = window.location.href.split('?');
if (s.length > 1) {
if (!document.getElementById('closed-flg').checked) {
popup = window.open('', 'popup');
popup.close();
}
}
}
</script>
</head>
<body>
<input type="checkbox" id="closed-flg"/>
<a href="#" onclick="closeWindow();">Close Popup</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment