微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – 如果有未读电子邮件,如何使屏幕闪烁

当有未读的电子邮件时,我正在寻找使整个屏幕闪烁红色或任何颜色的任何方法.它可以用于任何电子邮件客户端.我做了很多谷歌搜索,找不到任何东西.雷鸟的附加组件会产生一些闪烁的通知,但它只会在屏幕的右下角显得非常小.

我想到的可能是Firefox或Chrome的一些附加组件,它允许我编写可在Gmail上运行的自定义css和javascript,并使闪烁发生.
任何想法都非常感谢.

我知道这不是你经常提出的问题,但你们都很棒,我不知道还有什么地方可以转.如果有一个更好的论坛可以解决这类问题,你也可以告诉我.

谢谢!

最佳答案
我不是制作Chrome插件,而是让窗口标题闪烁或使用HTML5通知.创建一个简单页面,轮询您的IMAP Gmail以获取邮件,并在大型iFrame中包含Gmail.如果找到新消息,则外部窗口可以发出通知.

HTML5通知http://www.html5rocks.com/en/tutorials/notifications/quick/

闪烁标题(从this采用):

var newMailBlinker = (function () {
    var oldTitle = document.title,msg = 'New Mail!',timeoutId,blink = function() { 
            document.title = document.title == msg ? ' ' : msg; 
        },clear = function() {
            clearInterval(timeoutId);
            document.title = oldTitle;
            window.onmousemove = null;
            timeoutId = null;
        };

    return function () {
        if (!timeoutId) {
            timeoutId = setInterval(blink,1000);
            window.onmousemove = clear;
        }
    };
}());

PHP民意调查Gmail IMAP(从this采用):

$t1=time();//mark time in
$tt=$t1+(60*1);//total time = t1 + n seconds

do{
    if(isset($t2)) unset($t2);//clean it at every loop cicle
    $t2=time();//mark time
    if(imap_num_msg($imap)!=0){//if there is any message (in the inBox)

        $mc=imap_check($imap);//messages check
        //var_dump($mc); die;//vardump it to see all the data it is possible to get with imap_check() and them customize it for yourself
        echo 'New messages available';

    }else echo 'No new messagens';

    sleep(rand(7,13));//Give Google server a breack
    if(!@imap_ping($imap)){//if the connection is not up
        //start the imap connection the normal way like you did at first
    }

}while($tt>$t2);//if the total time was not achivied yet,get back to the beginning of the loop

jQuery AJAX轮询到您的IMAP脚本(从this采用):

// make the AJAX request
function ajax_request() {
  $.ajax({
    url: '/path/to/gmail/imap/checkMessages.PHP',dataType: 'json',error: function(xhr_data) {
      // terminate the script
    },success: function(xhr_data) {
        console.log(xhr_data);
        if (xhr_data.status == 'No new messages') {
            setTimeout(function() { ajax_request(); },15000); // wait 15 seconds than call ajax request again
        } else {
            newMailBlinker(); // blink the title here for new messages
        }
    }
    contentType: 'application/json'
  });
}

显然你不会使用jQuery和PHP进行轮询.选择一个进行投票.我建议让客户端进行轮询,并在每次连接时检查一次IMAP.话虽这么说,这些片段应该让你开始:)

原文地址:https://www.jb51.cc/html/425938.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐