Possible to flash a Browser window using Javascript?

后端 未结 5 1116
萌比男神i
萌比男神i 2020-12-05 22:04

Like many programs flash their window on the taskbar / dock to alert the user to switch to the program,

Is it possible to flash the

5条回答
  •  佛祖请我去吃肉
    2020-12-05 22:48

    @Hexagon Theory: Why would you ever rewrite the whole head element just to change the value of one element in the head? Your solution is horribly inefficient on multiple levels.

    
    
    
    
    
    
    
    
    

    flash.js:

    function Flasher(speed) {
      var elem = document.getElementById('changeMe');
    
      this.timer = setTimeout(function() {
        elem.href = elem.href ==  'on.png' ? 'off.png' : 'on.png';
      }, speed);
    
      this.stop = function() { clearTimeout(this.timer); }
    }
    
    /* sample usage
     *
     * var flasher = new Flasher(1000);
     * flasher.stop();
     */
    

    It didn't really have to be a class but it helped keep the global namespace clean. That's untested but if simply changing the href doesn't work for some reason, clone the link node, change the href and replace the old link with the cloned one.

提交回复
热议问题