开发者

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

开发者 https://www.devze.com 2023-04-03 17:04 出处:网络
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>

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

精彩评论

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