Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 241
Sefik_m Avatar asked Feb 16 '14 06:02

Sefik_m


People also ask

What is the browser tab title called?

The page title is defined in the HTML header and is shown as the tab name in a browser. Whatever is defined in the <title></title> tag is shown as the tab name in the browser window and as the title of the page in the search engine results pages. The page title is shown in the Google Search Results.

Can you rename a tab in Chrome?

Quick rename can be done by right-clicking anywhere in the page and click on "Rename Tab". Changelog: https://github.com/sylouuu/chrome-tab-modifier/releases About Permissions: All websites are required as the extension needs to update each visited website to do its job.


2 Answers

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>
like image 97
Chris Moutray Avatar answered Oct 12 '22 13:10

Chris Moutray


$(window).focus(function() {
   document.title = 'defult title';
});

$(window).blur(function() {
   document.title = 'you went?';
});
like image 22
Govind Singh Avatar answered Oct 12 '22 12:10

Govind Singh