Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- // Title when tab has focus
- var fTitle = 'I promise, Jack!';
- // Title rotation list when tab is "blurred" (doesn't have focus)
- var bTitles = [
- 'Come back!',
- '*blows whistle*'
- ];
- // Title rotation interval in milliseconds (e.g. 2000 = 2 seconds)
- var interval = 2000;
- var bti = 0, iv;
- function onFocus () {
- if (iv) {
- clearInterval(iv);
- iv = null;
- }
- document.title = fTitle;
- }
- function onBlur () {
- document.title = bTitles[bti++ % bTitles.length];
- if (bTitles.length > 1 && !iv) iv = setInterval(onBlur, interval);
- }
- document.title = fTitle;
- if (window.addEventListener) {
- addEventListener('focus', onFocus);
- addEventListener('blur', onBlur);
- } else if (window.attachEvent) {
- attachEvent('onfocus', onFocus);
- attachEvent('onblur', onBlur);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement