Skip to main content

Posts

Showing posts with the label html

Changing chrome title tab when users leave

The other day I was on  https://fabriceleven.com/ reading one of their blogs and when I tabbed away I saw the title change and I thought it was cool as I had not seen anyone else use it before even though its pretty simple. So I went about doing it myself. I've done it in pure JS as a lot of the examples are jQuery and for simple things like this you don't need a library. You can see this working on this page just click on another tab then come back. Below is the code I used to achieve this. Simply put I get the html title tag. Add an event for when the user is away or using the page with blur and focus on the window. Then I pick a random string to display when they are away. <!DOCTYPE html> <html> <head> <title>Hi this is the original title</title> </head> <body> <p> lorem ipsm </p> </body> <script type="text/javascript"> var title = document.querySelector("title"); wind