如何在卸载之前保存鼠标坐标


How to save mouse coordinates onbeforeunload?

我可以用这个动态跟踪鼠标坐标

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

这样,每个鼠标上的数字都会动态移动。我想做的是保存所有坐标。它应该在卸载之前保存它。如何保存所有数字?我正在考虑在卸载之前附加一个 iframe

保存.php坐标=162x412-143x716-678x12

我该怎么做?

试试这样的事情

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

然后

window.onbeforeunload = function() {
    $.post( your_url , moves.join('-'));
}

试试这种方法...

一种将这些坐标保存在隐藏变量中并在事件"onbeforeunload"上调用该隐藏变量值以获取它们并保存必要的方法。