Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Created June 13, 2013 02:53
Show Gist options
  • Save pinzolo/5770906 to your computer and use it in GitHub Desktop.
Save pinzolo/5770906 to your computer and use it in GitHub Desktop.
子画面を開き特定のボタンを非活性にする。子画面が閉じられたらボタンを活性化させる。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>親画面</title>
<style>
input {
width: 120px;
}
</style>
</head>
<body>
<h1>親画面</h1>
<form action="#" method="post">
<input type="button" id="openChild" name="openChild" onclick="openChildWindow()" value="ポップアップ開く" />
<br />
<ul>
<li><input type="button" id="btn1" name="btn1" value="非活性にする" /></li>
<li><input type="button" id="btn2" name="btn2" value="非活性にしない" /></li>
<li><input type="button" id="btn3" name="btn3" value="非活性にする" /></li>
<li><input type="button" id="btn4" name="btn4" value="非活性にしない" /></li>
</ul>
</form>
<script>
function openChildWindow() {
var btn1 = document.getElementById("btn1");
btn1.setAttribute("disabled", "disabled");
var btn3 = document.getElementById("btn3");
btn3.setAttribute("disabled", "disabled");
var child = window.open("child1.html", "child", "scrollbars=1,resizable=1,toolbar=0,menubar=0,location=0,directions=1,status=0");
child.focus();
var timer;
timer = setInterval(function() {
if (child.closed) {
btn1.removeAttribute("disabled");
btn3.removeAttribute("disabled");
clearInterval(timer);
}
}, 1000);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment