Tell me how cleverly implement script execution (javascript) in just one tab? Ie, if the page is open, the function is executed on it. If you open another tab at the same time with the same page, the function will not be executed. If you close the first, then the second should earn.

    1 answer 1

    Vkontakte is an implementation of an audio player according to this scheme, i.e. music is played only in one tab, in the rest there is a pause, you can read http://habrahabr.ru/post/153937/ for details. As I understand it is necessary to store the window identifier in LocalStorage, when closing a tab, catch the close event and notify LocalStorage that the tab is inactive, then the second tab should intercept this event and record its identifier in LocalStorage.

    • I had a thought about this, but did not learn how to catch the tab closing. - maza51