相容 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>
如果你寬度設定的沒問題的話我認為你這個問題的原因應該是第二條