javascript - Closing window from another window -


there 2 child windows b , c. , parent window a. want close c window when user clicks button in b.

window.opener() gives reference parent object. testing purposes lets assume c window name "name". below code invoked b should close c window.

but doesn't work.

  var windowobjectreference = window.opener.open("www.google.com" , "name");   windowobjectreference.close(); 

any idea how this?

since parentwindow has reference child windows, use parent window set handler of button in b child window. like:

var windowb = window.open( ... ),     windowc = .... ,     buttonb = windowb.document.queryselector(...yourbuttonreference...); buttonb.onclick = function() {     windowc.close();     window.open('http://www.google.com'); } 

if don't want close c window, try replacing window.location of c window google. parent window has references, it's easier have parent window opening/closing instead of having child windows try access siblings.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -