O
O
oe24y2020-12-06 08:43:21
JavaScript
oe24y, 2020-12-06 08:43:21

How does JavaScript know that the page is open and not collapsed?

There are sites that understand that the page is open and look at it.
How to implement this in JavaScript?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danil Samusev, 2020-12-06
@oe24y

// Проверка активна ли в настоящий момент вкладка браузера
var isActive = true;
function onBlur() { // окно теряет фокус
    isActive = false;
05
// что-то делаем
}

function onFocus() {// окно получает фокус
    isActive = true;
// что-то делаем
}
if (/*@[email protected]*/false) { // для Internet Explorer
    document.onfocusin = onFocus;
    document.onfocusout = onBlur;
} else {
    window.onfocus = onFocus;
    window.onblur = onBlur;
}

Source

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question