1
Hello, everybody.
I am trying to create a project, whose function is to identify the time the page is open (eg if it was 1 or 2 minutes open). When closed, save time information in the database.
However, I am a negation with javascript, jquery and the like. Follow the example code:
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var aberturaPagina;
$(window).ready(function () {
aberturaPagina = new Date().getTime();
});
$(window).on('beforeunload', function () {
var fechoPagina = new Date().getTime();
var tempoAberto = (fechoPagina - aberturaPagina) / 1000;
$.ajax({
type : "POST",
url : "http://url.exmplo.com.br/codigo_db.php?id=1&tempo=" + tempoAberto,
sucess : function(html){
$('.div').html(html);
}
})
});
</script>
When you run the page, nothing happens!
I built this Frankenstein with codes from some forums, someone can help me fix?
Perfect! Thank you very much. Worked with synchronous request
– Márcio Teixeira