Flash title bar

I am trying to make the title bar blink using very simple HTML. I gave him a chance, but the code below does not seem to work, and I have no idea why. Also, is there a way to make the text of the title bar, but only if the user is not viewing the current browser page?

My attempt:

function Flash() {
            window.setTimeout(function() {
            alert(document.title);
                document.title = (document.title == "Company" ? "Company - flash text" : "Company");
            }, 1000);

            this.stop = function() { 
                document.title = "Company";
                clearTimeout(this.timer);
            }
        }
+2
source share
2 answers

a duplicate of this causes my browser to flash as an indicator but since I wrote this script now:

<script>
var timer="";
var isBlurred=false;
window.onblur=function() {
  isBlurred = true;
  timer=window.setInterval(function() {
    document.title = document.title == "Company" ? "Company - flash text" : "Company";
  }, 1000);
}
window.onfocus=function() { 
  isBlurred = false;
  document.title = "Company";
  clearInterval(timer);
}
</script>

The jQuery version is not much different (but not verified)

var timer="";
var isBlurred=false;
$(window).on("blur",function() {
  isBlurred = true;
  timer=window.setInterval(function() {
    document.title = document.title == "Company" ? "Company - flash text" : "Company";
  }, 1000);
}).on("focus",function() { 
  isBlurred = false;
  document.title = "Company";
  clearInterval(timer);
});
+6
source

() document.title, ( , ). . , - visibilityChange (actionFunction). -, document.title - comeBackAlerts(). :

/* , actionFunction */

    function visibilityChange(actionFunction){

        window.focus(); /* window.onfocus   = infoIn;  */

        var hidden = "hidden";

        /* Standards: */
        if (hidden in document){
            document.addEventListener("visibilitychange", actionFunction);
        }
        else if ((hidden = "mozHidden") in document){
            document.addEventListener("mozvisibilitychange", actionFunction);
        }
        else if ((hidden = "webkitHidden") in document){
            document.addEventListener("webkitvisibilitychange", actionFunction);
        }
        else if ((hidden = "msHidden") in document){
            document.addEventListener("msvisibilitychange", actionFunction);
        }
        /* IE 9 and lower: */
        else if ("onfocusin" in document){
            document.onfocusin = document.onfocusout = actionFunction;
        }
        /* All others: */
        else{
            window.onpageshow = window.onpagehide
            = window.onfocus = window.onblur = actionFunction;  
        }
    }       

/* , */

    var comeBackAlerts  = (function () {
            var oldTitle                    = document.getElementsByTagName('h1')[0].innerText; /* document.title; */
            var msg                         = "Arbir.ru";
            var intervalId;
            var blink       = function(){
                    intervalId = setInterval( function() { 
                        /* document.title = document.title == msg ? ' ' : msg; */ 
                        if(document.title == msg){
                            document.title = oldTitle;
                        }
                        else{
                            document.title = msg;
                        }
                    }, 1000);
                };
            var clear       = function() {
                clearInterval(intervalId);
                document.title              = oldTitle;
                window.onmousemove          = null;
                window.onmouseout           = null;
                intervalId                  = null;
            };
            return function () {
                if (!intervalId) {
                    blink();
                    window.onmousemove      = clear;
                }
            };
    }());

/* */

    visibilityChange(comeBackAlerts);

, , .

+1

All Articles