相容 Google、Firefox、360系列瀏覽器的案頭通知(實用),Google360

來源:互聯網
上載者:User

相容 Google、Firefox、360系列瀏覽器的案頭通知(實用),Google360
相容 Google、Firefox、360系列瀏覽器的案頭通知(實用)

    本文為工作中總結而來,並參考了大量網路資源,希望對有同樣需求的朋友提供協助。
    參考資源如下(部分):
    http://xsk.tehon.org/den/index.php/category/tech/html5-audio-notifications.html
    http://ttsvetko.github.io/HTML5-Desktop-Notifications/#
    http://www.cnblogs.com/meteoric_cry/archive/2012/03/31/2426256.html

     

1、通知授權問題

       開啟案頭通知需要檢測當前瀏覽器是否支援並且有授權,範例程式碼如下:

    if (!("Notification" in window) && !window.webkitNotifications) {//不支援  alert("很遺憾,您當前瀏覽器不支援該功能!\n建議在360、Google、Firefox等瀏覽器上使用此功能");    } else if (Notification.permission != undefined && Notification.permission != null) {if (Notification.permission != "granted") {/*未授權(Google、Firefox)  此處省略 300行*/}    } else if (Notification.permission == null || Notification.permission == undefined) {if (window.webkitNotifications.checkPermission() != 0) {/*未授權(360系列) 此處省略 300行*/}    }else {/*支援並已授權(此處省略 300行) */    }

      如下:




2、案頭通知調用方法

    案頭通知調用方法(windowsNotify)如下:

/* * 案頭通知 * strNewsContent:通知的內容 */function windowsNotify(strNewsContent) {if (!("Notification" in window) && !window.webkitNotifications && window.webkitNotifications.checkPermission() != 0)return;if (Notification.permission == null || Notification.permission == undefined)windowsNotify360(strNewsContent);else if (Notification.permission === "granted")windowsNotifyFFAndGE(strNewsContent);else if (Notification.permission !== 'denied') {Notification.requestPermission(function (permission) {if (!('permission' in Notification))Notification.permission = permission;if (permission === "granted")windowsNotifyFFAndGE(strNewsContent);});}}//案頭通知(相容360)function windowsNotify360(strNewsContent) {if (window.webkitNotifications && window.webkitNotifications.checkPermission() == 0) {var notify = window.webkitNotifications.createNotification(    "http://www.fx678.com/corp/images/aboutus/htw.jpg",            '匯通-新聞中心',    strNewsContent    );//設定定時撤銷機制,防止通知長時間顯示不被關閉notify.ondisplay = function (event) {setTimeout(function () {event.currentTarget.cancel();}, 10000);};//下面是定義點擊事件,類似地還可定義其它事件notify.onclick = function () {window.focus();this.cancel();};//彈出notify.show();} else if (window.webkitNotifications) {window.webkitNotifications.requestPermission(windowsNotify360);}}//案頭通知(相容Firefox、Google)function windowsNotifyFFAndGE(strNewsContent) {var notification = new Notification('匯通-新聞中心', { body: strNewsContent, icon: "http://www.fx678.com/corp/images/aboutus/htw.jpg" });//設定定時撤銷機制,防止通知長時間顯示不被關閉notification.ondisplay = function (event) {setTimeout(function () {event.currentTarget.cancel();}, 10000);};//下面是定義點擊事件,類似地還可定義其它事件notification.onclick = function () {window.focus();this.cancel();};}

如下:


以上內容就是這些,如有好的方法歡迎大家多多賜教指正!謝謝。





Firefox瀏覽器,Google瀏覽器,360瀏覽器哪個好

個人喜歡Firefox,各種擴充,打造自己喜歡的瀏覽器,擴充很給力
 
css 只相容Firefox,不相容Google與 360及IE9\IE8 救助

Firefox的錯誤修正能力相對來說是比較差的,也就是說一般的css的小問題不會顯示出來,所以你以後寫css的時候的得加強一下
你這個問題一般來容易錯位的原因有:
1、寬度計算的太緊,也就是子級寬度總和正好等於父級的寬度,有時候某些樣式會導致不同瀏覽器顯示的值會有所不同,比如margin左右邊距或者boder的計算值等;
2、html代碼的排布順序問題,比如兩個同級的標籤一個加了float:left;一個加了float:right;那麼一般防止出錯的話會把設定了float:right;的標籤寫在設定了float:left;的標籤上面,也就是先謝左浮動的再寫右浮動的;這樣瀏覽器解析的時候就相當於先右浮動再左浮動;舉例如下:
<div style="width:300px;height:22px;">
<div style="float:left;width:150px;height:22px;"></div>
<div style="float:right;width:140px;height:22px;"></div>
</div>
改為:

<div style="width:300px;height:22px;">
<div style="float:right;width:140px;height:22px;"></div>
<div style="float:left;width:150px;height:22px;"></div>
</div>

如果你寬度設定的沒問題的話我認為你這個問題的原因應該是第二條
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.