How to add on to an existing onclick event?
I'm current开发者_C百科ly writing a Greasemonkey script for a page, so I can't modify the script myself.
There is a form submit button on the page. When you click this button, it executes some fancy AJAX calls and such to update the page and do serverside things. What I'm trying to is basically set a "lastClick" value when the button is clicked.
I want to add the code GM_setValue("lastClicked", (new Date()).getTime().toString())
to store the last time the button was clicked (for future uses of the script, it will actually do something with this date).
How exactly can I accomplish this?
Or just add a separate listener without messing with the original one
document.getElementById("yourelementID").addEventListener("click", function(){
GM_setValue("lastClicked", (new Date()).getTime().toString())
}, false);
This works no matter how the original listener was added and does not alter the call chain.
精彩评论