Change Tab Title with JavaScript
Changing the tab (or window) title is an age old practice. Gmail does it to notify the user of a new chat message and this blog does it to update the tab title after a new page loads via AJAX. How is it done? By setting a property on the document
object, of course:
That property, of course, is document.title
:
document.title = 'Hello!'; // New title :)
One common misconception is that you change the window.title
property, but you must use the document
object, otherwise you'll see no effect. You'll oftentimes see a setInterval
used with document.title
to quickly change title to get the user's attention.
You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...
MooTools has always gotten a bit of grief for not inherently using and standardizing namespaced-based JavaScript classes like the Dojo Toolkit does. Many developers create their classes as globals which is generally frowned up. I mostly disagree with that stance, but each to their own. In any event...
Although it's possible to achieve opacity using CSS, the hacks involved aren't pretty. If you're using the MooTools JavaScript library, opacity is as easy as using an element's "set" method. The following MooTools snippet takes every image with the "opacity" class and sets...
The responsibilities taken on by CSS seems to be increasingly blurring with JavaScript. Consider the -webkit-touch-callout
CSS property, which prevents iOS's link dialog menu when you tap and hold a clickable element. The pointer-events
property is even more JavaScript-like, preventing:
click actions from doing...
This is great – in 15 years of working in web design the thought of changing page title never crossed my mind. Could be useful though, cheers!
If you want to be evil about it change it to:
And see how many people wonder what is unread :)
If that’s not in evil.js, it should be added immediately
Thats pure evil.
That’s really nice – I always did that via
getElementsByTagName
andinnerHTML
, but this solution’s way more convenient.Of-course this is tricky. It also affects DOM document ( element in HTML). Also In XUL, retrieving
document.title
before document gets completely loaded has unfixed behavior (document.title
might pull an empty result or may effect-less.)I’m happy to be corrected on this, but if you change the tab title after a screen reader initially caches the page, they are not informed of this change. So, if you are changing the page for a relevant reason, could this be a problem? The page title is the first thing screen readers hear when a page loads, and it is like a road map to where they are, where they want to be.
This is such a simple tweak and can make us look our website state of the art!