Home > Article > Web Front-end > Example of js monitoring browser tab page switching
I have been searching online for a long time, and I have always wanted to implement this kind of monitoring event similar to the window switching and title changing on the Ele.me website. . .
The hard work paid off and I finally found it. . .
Coincidentally, the questioner also used Ele.me as an example. . .
https://zhidao.baidu.com/question/754828658481567564.html
Javascript code
<script> </p> <p>document.addEventListener('visibilitychange',function(){ </p> <p> if(document .visibilityState= ='hidden') { </p> <p> normal_title=document.title; </p> <p> document.title='(づ ̄3 ̄)づ'; </p> <p> } </p> <p>else </p> <p> document.title=normal_title; </p> <p>}); </p> <p></script>