4
I found on the Internet the following code:
<script type="text/javascript">
var popup = null;
function Abrir() {
if (popup!=null && popup.closed)
alert("A Janela foi fechada.n Abrindo novamente.");
if (popup!=null && !popup.closed){
}
else {
popup = window.open("http://www.google.com","Jan","height=350,width=200");popup.focus();
}
setTimeout("Abrir()", 2000); //javascript trabalha com milesimos
}
</script>
It fits well in the system I want to do, which checks if the open tab is still open, but needs an adjustment that I do not know how to do.
This code is in loop, when he gives the message that the window has been closed, he opens it again. Could he have just sent the message? And send only once not to be in charge all the time? That is, to make the timer run only until it detects that the window has been closed, so it sends the alert and stops executing the function again.
Updating: I was able to assemble the following code, what do you think?
<script type="text/javascript">
var popup = null;
function Abrir() {
popup = window.open("http://www.google.com","Jan","height=800,width=600");popup.focus();
setTimeout("Verifica()", 2000);
}
function Verifica() {
if (popup!=null && popup.closed){
$("#aguardetop").hide("slow");
$("#sucessotop").fadeIn();
Adiciona();
return;
}
if (popup!=null && !popup.closed){
}
setTimeout("Verifica()", 2000);
}
</script>
You want to use the
setTimeout
same? it will run the code once only after 2 segs, is it not thesetInterval
you want to use?– stderr
the
SetTimeout
in case it is to run the check until the time the user closes the popup, since I could not work with theonbeforeunload
– GGirotto
Actually I didn’t see much difference rsrs
– GGirotto