How to change tab name in browser when user disconnects from my site

So, I make a site and everything is beautifully done, but I do not know what many things are with javascript.

I was looking for something that will help me with this and find similar things, but in my case it will not work.

This is the problem / idea:

  • The user is on my site, and, for example, the name of the page. Hello (tag) Then the user clicks on another tab in the browser, but does not close my site. When this happens, my page title changes, for example. You have gone? When he clicks on my tab, the title returns to default again.

So, if someone can help me with the code and explain it a bit.

Thanks.

+8
javascript jquery html
source share
3 answers

You need to use the onblur and onfocus events for the window object.

So something like this (this is native javascript, without jquery).

<script> window.onblur = function () { document.title = 'you went?'; } window.onfocus = function () { document.title = 'you came back'; } </script> 
+12
source share
 $(window).focus(function() { document.title = 'defult title'; }); $(window).blur(function() { document.title = 'you went?'; }); 
+1
source share

You can use:

 window.addEventListener('blur',function(){ alert("please Came Back"); document.head.title = "your tilte" }); window.addEventListener('focus',function(){ alert("Hi"); document.head.title = "your tilte" }); 
0
source share

All Articles