Code for tab / window / browser tab flash

Asked

Viewed 1,206 times

0

Good afternoon, as I am not good at javascript, so I need the masters here to help me. I am building a browser system for a company. In this system will happen several events, and as I wrote in the title, I need a code so that when the user receives a new message of some event occurred, the browser tab is flashing.

I know I can do this with alert javascript (I believe), and if I have to do it that way, I would like something simple, and it would disappear when the user opened that window that is blinking.

I found an example in the stackoverflow of "gringa" https://stackoverflow.com/questions/3381462/how-to-create-the-title-alert-effect-like-facebook, that meets, in part, this need, because it keeps changing the title and this draws the user’s attention. But I wish there was a way to blink, if there is, of course.

Follow the code I found:

    <script type="text/javascript">

    (function () {

    var original = document.title;
    var timeout;

    window.flashTitle = function (newMsg, howManyTimes) {
    function step() {
    document.title = (document.title == original) ? newMsg : original;

    if (--howManyTimes > 0) {
        timeout = setTimeout(step, 1000);
      };
    };

    howManyTimes = parseInt(howManyTimes);

    if (isNaN(howManyTimes)) {
       howManyTimes = 5;
    };

    cancelFlashTitle(timeout);
    step();
    };

    window.cancelFlashTitle = function () {
    clearTimeout(timeout);
    document.title = original;
  };

  }());

  </script>

Suggestions are very welcome.

Thank you

  • Friend I believe you will not be able to do the effect you want. A tip is to use desktop notifications, take a look at this plugin https://github.com/ttsvetko/HTML5-Desktop-Notifications. Once the user allows the notifications, he starts receiving the messages on the desktop even with the browser minimized. I use this way and my users liked it. I will look for other plugins, if you know something put for you.

1 answer

-2

<script>
    var titulo = "- Teste -"
    var titulo = titulo + "          " 
    i = "0"
    var tmptitulo = "" 
    var velocidade = "50"
    const scrollTitulo = () => {

    if (!document.all && !document.getElementById)
        return

    document.title = tmptitulo + titulo.charAt(i)
    tmptitulo = tmptitulo + titulo.charAt(i)
    i++
    if (i == titulo.length)
    {
        i = "0"
        tmptitulo = ""
    }
    setTimeout("scrollTitulo()", 35)
}

window.onload = scrollTitulo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.