0

I have seen some snippets to get the mouse position and read a bit about jquery-one. Would someone please make or show me an example of detecting the position of the mouse whenever it is moved and saving the sequence of the coordinates and clicks with click coordinates to an array (or delimited string variable might be better) as it runs and then when the user navigates away from the page (or clicks a link on the page) it will POST the event log to a php file? I can write the php part.

Thanks

1 Answer 1

0

You can detect mouse movement with window.onmousemove. The coordinates are accumulated in xList and yList, and when the window unloads the unload() function is called. From there you can do whatever you want with the lists, but be warned, they will get very long very fast!

window.onmousemove = mouseMoved;
window.onunload = unload;

var xList = [];
var yList = [];

function mouseMoved(evt){
    evt = evt || window.event; //compatibility with IE and other browsers
    xList.push(evt.clientX);
    yList.push(evt.clientY);
}

function unload(){
    //do something with xList and yList
    alert("unloading");
}

See example on JSFiddle. It doesn't show the unload functionality, but it displays the current coordinates in a div.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.