Possible to flash a Browser window using Javascript?

后端 未结 5 1125
萌比男神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:52

    Hey, another interesting solution to this question hit me just now. Why not really grab the user's attention by making the icon flash in their browser? You could, for example, make two icons (on.png and off.png in my example below) and repeatedly swap them out to really catch a user's eye. The following is a bare-bones implementation; do keep in mind that you will need to reference this script remotely or put it in the body of the page because it uses a method that repeatedly replaces the content of the tag. Give it a try, though; I rather like the simplicity of it.

    page.html:

    
    
    
    
    
    
    
    
    

    flash.js:

    var timer, speed = 175;
    function flash()
     {
    head_html = document.getElementsByTagName('head')[0].innerHTML;
    if (head_html.indexOf('href="on.png"') != -1)
    document.getElementsByTagName('head')[0].innerHTML = head_html.replace('on.png', 'off.png');
    else
    document.getElementsByTagName('head')[0].innerHTML = head_html.replace('off.png', 'on.png');
    timer = setTimeout('flash()', speed);
     }
    
    function kill_flash() {clearTimeout(timer);}
    
    flash();
    

提交回复
热议问题