Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save mouse coordinates onbeforeunload?

I can track mouse coordinates dynamically with this

$(document).ready(function()
{
  $().mousemove(function(e)
{
 $('p').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
});
});    

With this, the numbers change on each mouse move dynamically. What I want to do is to save all coordinates. It should save it onbeforeunload. How to save all numbers ? I am thinking of append an iframe onbeforeunload like

save.php?coords=162x412-143x716-678x12

How can I do this ?

like image 622
user198989 Avatar asked Dec 31 '25 23:12

user198989


2 Answers

Try something like this

var moves = [];
$().mousemove(function(e){
    moves.push(e.pageX + "x" + e.pageY) 
});

then

window.onbeforeunload = function() {
    $.post( your_url , moves.join('-'));
}
like image 82
Johntor Avatar answered Jan 03 '26 13:01

Johntor


try this approach...

a way of saving these coordinates in a hidden variable and calling that hidden variable values on the event "onbeforeunload" to obtain them and save necessary..

like image 34
Sanath Avatar answered Jan 03 '26 12:01

Sanath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!