0

I've been using beforeunload to check my users leaving web pages, and it all works well, the thing is, now I want to run a function only when the user is leaving my website / domain.

So for example, going from mywebsite.com to mywebsite.com/app wouldn't trigger the function, but going from mywebsite.com to google.com would.

I don't care about what website they're going to, I just want to know if they're staying on my domain or not.

I can't get anything on the parameter of the beforeunload function. I've read a bit around the web, but no cigar. Any ideas?

Fábio Santos
  • 199
  • 1
  • 2
  • 16
  • 2
    I think you can't do this. It sounds like privacy-loss for the users to me, to know where are they going to go from your own website. – lilezek Sep 25 '17 at 16:28
  • I don't care about what website they're going to, I just want to know if they're staying on my domain or not. – Fábio Santos Sep 25 '17 at 16:30
  • @FábioSantos that's not possible. You can only see the previous page from the new one, not the other way around. One solution would be to place a listener on every `a` element in your HTML and check what its target domain is, and act appropriately when clicked - but that's not nice at all. – Rory McCrossan Sep 25 '17 at 16:31

0 Answers0