1

I'm developing a service, which renders a series of Resources on a page. Resource - is a record in database, which has "url" and "visited" fields.

When user click on resource url, it will be marked as "visited: true" in database via sending ajax PUT request. It works well, until user decides to open url in new tab. When I open context menu for given url and choose "Open in new Tab", javascript does't catches this event and record in database will not be updated.

In this question Javascript Event for "Open in new Tab" they adviced to change "click" handler to "onmousedown". But, this handler catches just opening context menu, even, when I close it, without choosing anything.

Is there any standard way to handle "Open in new tab" event?

Thanks!

Community
  • 1
  • 1
AntonAL
  • 16,692
  • 21
  • 80
  • 114

1 Answers1

3

Make resource URLs redirect to your site first (yoursite.com/record_click?to=actual.url). When the user clicks the URL, regardless of the way, you can track the URL opening - the AJAX request might not even be needed any more.

Koterpillar
  • 7,883
  • 2
  • 25
  • 41