2016-11-15 39 views

回答

1

您可以捕捉任何文檔或點擊。也許更好的選擇是爲了不被其他點擊事件阻止(通過event.preventDefault)。

document.onmousedown = function (event) { 
    if (!event) {event = window.event;} 
    console.log("mousedown "+event.target, event); 
    // Post the event object here. 
}; 

使用jQuery:

$(document).on('mousedown', function (event) { 
    console.log("mousedown "+event.target, event); 
    // Post the event object here. 
}); 
0

您可以使用jQuery的click()方法來捕獲所有的鼠標事件是這樣的:

capture_mouse_clicks = []; 

$('#id').on('click', function(e) { 
    capture_mouse_clicks.push({ 
     event: 'click', 
     target: $(this).attr('id'), 
    }) 
}) 

希望這有助於!

0

您可以在標籤上放置onclick處理程序,但在頁面導航時您的ajax可能會失敗,但如果服務器響應很快,則xhr會在中途取消。

您可以在代碼中添加輕微的JS延遲,就在您的異步ajax之後。這可能有幫助。

0

對於您需要將它們存儲在一個全球性的陣列或可以在整個頁面訪問的全局變量。你可以通過編寫一個捕獲事件的函數捕獲整個事件,所以我更喜歡一個包含所有事件對象的數組。

接下來,當您離開頁面時,使用window.onbeforeunload事件並使用ajax調用來進行post調用並將對象數組保存到數據庫中。

上述兩個步驟的代碼比較簡單。

相關問題