Javascript 检测单击并比较URL
我需要检测鼠标点击后,页面加载和功能是删除广告执行 检测到鼠标点击后,它将比较URL,并且应该在每次鼠标点击时进行比较 我试过使用谷歌的东西,但不明白,所以我换成了纯JSJavascript 检测单击并比较URL,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我需要检测鼠标点击后,页面加载和功能是删除广告执行 检测到鼠标点击后,它将比较URL,并且应该在每次鼠标点击时进行比较 我试过使用谷歌的东西,但不明白,所以我换成了纯JS let host = window.location.host; // www.adjaranet.com let path = window.location.pathname; // /... let href = window.location.href; // http // aler
let host = window.location.host; // www.adjaranet.com
let path = window.location.pathname; // /...
let href = window.location.href; // http
// alert(path); // movie section = /Movie/main // homepage = /
if (href == "https://www.adjaranet.com/") {
function deletor() {
// some code that executes...
}
deletor();
// Here I want to detect mouse clicks and then compare the URLs
}
如果单击鼠标并更改页面(url),则应运行另一个单独的功能。类似的功能将侦听页面单击:
window.onload = function() { // after page has loaded
function onMouseClick(event) {
// check url
if (window.location.href === 'https://www.adjaranet.com/') {
// your code here
}
}
// register event listener so onMouseClick is called whenever a click happens
document.addEventListener("click", onMouseClick);
};
document.querySelector("html").addEventListener("mousedown", e => {
console.log("Clicked!") // whatever function you want to run here
})
将其放入TamperMonkey脚本(或类似脚本)中,以便在您点击某些页面时自动运行
然而,实际上要删除广告,只需在页面上查找元素并将其删除,或者将其内部HTML更改为“
”。但是,请确保您首先处理元素不存在的情况,否则您可能会收到大量控制台警告/错误