Automatically close browser after alert

Asked

Viewed 682 times

0

How do I get the browser to automatically close after the alert?

<html>
<head>
</head>  
<body>
  <div onmouseover="showText();" onmouseout="javascript:alert('my alert');" id="div"></div>
</body>
</html>

function alert(){
  alert("my alert");
}
  • 1

    Close your browser all? It’s not a bit violent?

2 answers

2

Try to use:

window.close();

after the alert.

  • 2

    Can you post the answer more fully? With the call on onmouseout?

  • explains better?

  • So dude, seeing better, this window.close() method is only allowed when the window is opened by the window.open() method; Info: https://developer.mozilla.org/en-US/docs/Web/API/Window/close

  • But what would be the reason you want to close the tab or window? That’s not a good one.

0

You could do something like this:

function alerta(){
alert('my msg');
}
function fechar(){
window.close();
}
#algo{
width: 100px;
height: 100px;
background: darkcyan;
}
<div id='algo' onmouseover='alerta()' onmouseout="fechar()"></div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.