A
A
Andrey Okhotnikov2019-09-18 11:22:51
Web development
Andrey Okhotnikov, 2019-09-18 11:22:51

How to track the opening of a tab?

I need to make an ajax request every time I switch to a tab in the browser, i.e. if the user opened the site, then moved to another tab and returned to mine, the request is executed. How to track the moment when the user goes to the tab?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hzzzzl, 2019-09-18
@tsepen

https://developer.mozilla.org/en-US/docs/Web/API/D...
works for both tabs and "saved to home screen" pwa-apps so that the data is loaded when the user opens the app again

A
Alexey Nikolaev, 2019-09-18
@Heian

window.onfocus and window.onblur, if I understood the task correctly. The first event will be executed when the user goes to the tab, the second - when he leaves it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question