Created
February 12, 2018 15:56
-
-
Save junquera/347f9bce2e3249452a06b5cc4686d827 to your computer and use it in GitHub Desktop.
Manage father, son and brother windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| var sons = []; | |
| function newSon(){ | |
| var next = window.open('/'); | |
| sons.push(next); | |
| } | |
| function closeSons(){ | |
| var next = sons.pop(); | |
| while(next){ | |
| try{ | |
| next.close(); | |
| } catch(e){} | |
| next = sons.pop(); | |
| } | |
| } | |
| </script> | |
| <body> | |
| <h1 id="who">Parent</h1> | |
| <button onclick="newSon()">Open son</button> | |
| <a href="/" target="_blank"><button>Open "brother"</button></a> | |
| <button onclick="closeSons()">Close sons</button> | |
| <button id="suicide" onclick="window.close()" hidden>Close myself</button> | |
| </body> | |
| <script> | |
| if(window.opener){ | |
| var element = document.getElementById('who'); | |
| element.innerHTML = "Son"; | |
| var suicide = document.getElementById('suicide'); | |
| suicide.removeAttribute('hidden'); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment