Close JavaScript window

0

I'm trying to make the current window close with some kind of java script function. But I have not managed to achieve it. I have already used some methods but apparently they do not work unless the window is opened by means of a similar function, something that is irrelevant.

function Finalizar() {        

  var ventana = window.self;
  ventana.opener = window.self;
  ventana.close();

}

function Finalizar() {        

  parent.window.close();

}

function Finalizar() {        

  setTimeout("self.close();", 7000);

}

<button type="button" class="btn btn-primary" onClick="self.close();">Entendido</button>

<button type="button" class="btn btn-primary" onclick="javascript:self.close()" >Entendido</button>

This is the message I get from debugging the browser

Scripts may close only the windows that were opened by it.

Any information to help the problem?

    
asked by Bastian Salazar 09.02.2018 в 20:19
source

3 answers

3

If you want the current window to close just use this:

window.close();

And you do not have to do anything else, the code you want to use is when you have a parent or opened a popup from a parent window.

Only use it like this:

function Finalizar() {        
    window.close();
}

<button type="button" class="btn btn-primary" onClick="Finalizar();">Entendido</button>
    
answered by 09.02.2018 / 20:35
source
0

The javascript scripts can only close the windows they have opened themselves: Reference

    
answered by 10.02.2018 в 00:16
0

Since the last specification is not possible, as a security measure, unless you meet a series of detailed conditions in link

    
answered by 12.02.2018 в 17:54