Answer the question
In order to leave comments, you need to log in
How to track leaving the site in the manner of VK?
I'm doing a pet project, in fact, I want to secure the user and add tracking of all links, and if the host of this link does not match the host of my site, I'll give a warning. In principle, I understand how to do it, the key difficulty arises at the very first stage - click tracking. Unfortunately, at the moment I can’t give code examples, due to the fact that I’m on the phone, but simply put, I do this:
(I’m not sure that I wrote it correctly from memory, but he understands me and writes the object to the variable with a list of links on the page). And then I do
let links = document.getElementsByTagsName('a')
links.addEventListener('click', function () {
// и здесь код, который будет предупреждать юзера
});
Answer the question
In order to leave comments, you need to log in
let links = document.getElementsByTagName('a')
links.forEach(link => link.addEventListener('click', () => {}))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question