gpt4 book ai didi

javascript - 监听Chrome浏览器中的所有事件

转载 作者:行者123 更新时间:2023-11-28 19:57:23 25 4
gpt4 key购买 nike

我想听我的网站上发生的所有事件。我用monitorEvents()命令,但此命令仅将事件打印到控制台,我想为其设置一个回调函数,以对该数据进行一些操作,而不将其打印到控制台。

有什么聪明的方法可以做到这一点吗?

最佳答案

你可以尝试这样的事情:

var eventsList = ["mousedown", "mouseup", "click", "dblclick", "mousemove",
"mouseover", "mouseout", "mousewheel", "keydown", "keyup", "keypress",
"textInput", "touchstart", "touchmove", "touchend", "touchcancel", "resize",
"scroll", "zoom", "focus", "blur", "select", "change", "submit", "reset"];

var callbackFunction = function(element, eventName) {
console.log('Triggered event ' + eventName);
};

var elements = document.querySelectorAll('*');
for (var i = 0; i < elements.length; i++) {
for (var j = 0; j < eventsList.length; j++) {
var element = elements[i];
var event = eventsList[j];

element.addEventListener(event,
callbackFunction.bind(this, element, event), true);
}
}

关于javascript - 监听Chrome浏览器中的所有事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22305977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com