Skip to content

Instantly share code, notes, and snippets.

@tlareg
Created January 23, 2017 23:26
Show Gist options
  • Save tlareg/af3c88919a23bfa94c46cf624ca8ee15 to your computer and use it in GitHub Desktop.
Save tlareg/af3c88919a23bfa94c46cf624ca8ee15 to your computer and use it in GitHub Desktop.
parent-child-window-communication
<!doctype html>
<html>
<head>
</head>
<body>
<div>
<h1>CHILD WINDOW 2</h1>
</div>
<div>
<button class="back-btn">back</button>
</div>
<script>
document.querySelector('.back-btn').addEventListener('click', () => {
window.location.href = 'http://127.0.0.1:8080/src/child-window.html'
})
</script>
</body>
</html>
<!doctype html>
<html>
<head>
</head>
<body>
<div>
<h1>CHILD WINDOW</h1>
</div>
<div>
<input type="text" class="child-msg-input">
</div>
<div>
<button class="child-2-btn">child 2</button>
</div>
<div>
<button class="close-btn">close</button>
</div>
<script>
document.querySelector('.close-btn').addEventListener('click', () => {
const msg = document.querySelector('.child-msg-input').value
window.opener.onChildMsg(msg)
window.close()
})
document.querySelector('.child-2-btn').addEventListener('click', () => {
window.location.href = 'http://127.0.0.1:8080/src/child-window-2.html'
// window.location.href = 'https://pz.gov.pl/dt/login/login'
})
</script>
</body>
</html>
<!doctype html>
<html>
<head></head>
<body>
<div>
<h1>PARENT WINDOW</h1>
</div>
<div>
<button class="child-window-btn">CLICK ME!</button>
</div>
<div>
<h2>Child message:</h2>
<div class="child-msg"></div>
</div>
<script>
window.onChildMsg = (msg) => {
document.querySelector('.child-msg').innerHTML = msg
}
document.querySelector('.child-window-btn').addEventListener('click', () => {
const childWin = window.open(
'child-window.html',
'_blank',
`
height=600,
width=960,
status=no,
toolbar=no,
menubar=no,
location=no,
addressbar=no,
close=no
`
)
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment