Conversaciones » Desarrolladores
Delete event listener upon activation
add }, { once: true });
in the end
It does not work:
document.addEventListener("DOMContentLoaded", function() {
document.body.addEventListener("mouseover", async function(e) {
if (e.target && e.target.nodeName == "A") {
hyperLink = e.target;
await xhrHyperLink(hyperLink);
}, { once: true });
});
When adding { once: true }
to event mouseover
the event does not work - at all, and adding { once: true }
to event DOMContentLoaded
makes no change.
It should work though
I have added { once: true }
to Proxy Redirect. Please see for yourself, that the functionality to change links, as shown in the video is not working.
In the video, I present the issue caused by the event being executed more than once.
Answering to myself: Of course it does not work for links, because the "event listener" is directed at the element "body" document.body.addEventListener
.
Issue has been solved!
for (linkElement of document.links) {
linkElement.addEventListener("mouseover",
async function(e) {
if (e.target && e.target.nodeName == "A") {
hyperLink = e.target;
await xhrHyperLink(hyperLink);
}
},
{
once: true
}
);
}
Thank you hacker09 and Konf!
Greetings!
I am attempting to remove the event listener once it is called.
Whoever sees this, please consider helping.