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

html, javascript, jquery

Solution

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

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

<script>

window.onblur = function () { document.title = 'you went?'; }

window.onfocus = function () { document.title = 'you came back'; }

</script>

Problem

So I am making a website and everything is nicely done but I don't know that many things with javascript. I was searching for something that will help me with this and found some similar things but it doesn't work in my case. This is the problem/idea: - User is on my site and the page name is eg. Hello ( tag) Then the user clicks on the other tab in the browser but doesn't close my website. When that happens my page title changes to eg. You went ? When he clicks on my tab again title changes back to default one. So if someone can help me with the code and explain it a little bit. Thank you.

Original source