开发者

possible to detect click on an element using a greasemonkey-type user script?

Let's say I have a greasemonkey-type user script running on a page that has a div such as:

<div id="watchme">something</div>

Is it possible to detect if a user clicks on that div from within the user script? The logical way would be to have an onClick() written into the code, but since this is a user script I don't control the c开发者_开发问答ode.


Did you try attaching an event listener?

document.getElementById("watchme").addEventListener("click", yourHandler, false);

Note that assigning the onclick method may not work: see this.


document.getElementById("watchme").onclick = function(){
    alert("I've been clicked");
}

That's how you assign the onclick event in js.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜