`
zhhaogen
  • 浏览: 13413 次
  • 性别: Icon_minigender_1
  • 来自: 未知
社区版块
存档分类
最新评论

ie、chrome、firefox桌面通知实现、播放声音实现

 
阅读更多

 

/***
*
*@author zhhaogen@163.com
*
**/
var message=
{
	ieinjur:false,
	pmdtid:null,
	title:null,
	shtid:null,
	wstid:null,
	//播放声音
	playSound:function(src)
	{
		var div=document.getElementById("playercnt");//播放div
		if(div==null)
		{
			div=document.createElement("div");
			div.id="playercnt";
			div.setAttribute("style","display:none");
			document.body.appendChild(div);
		}
		if(document.createElement('audio').play==null)
		{
			//ie
			div.innerHTML="<EMBED id='player' src='"+src+"' hidden='true'  loop='false' autostart='true'>";
		}else
		{
			div.innerHTML="<audio id='player' src='"+src+"' hidden autoplay></audio>";
		}
	},
	//标题栏跑马灯
	titleScroll:function(msg,ops)
	{
		if(this.pmdtid!=null)
		{
			clearInterval(this.pmdtid);
			document.title=this.title;
			this.pmdtid=null;
		}
		if(ops=="stop")
		{
			 clearInterval(this.pmdtid);
			 document.title=this.title;
			 this.pmdtid=null;
			 return;
		}
		this.title=document.title;
		var n=0;
		var max=parseInt(ops)||1000;
		var pmd=function()
		{
			msg=msg+msg.substr(0,1);
			msg=msg.substr(1);
			document.title=msg+"  "+message.title;//原来标题加上消息标题
			n++;
			if(n>max)
			{
				clearInterval(message.pmdtid);
				document.title=message.title;
			}
		}
		this.pmdtid=setInterval(pmd,600);
	},
	//标题栏闪烁
	titleShan:function(msg,ops)
	{
		if(this.shtid!=null)
		{
			clearInterval(this.shtid);
			document.title=this.title;
			this.shtid=null;
		}
		if(ops=="stop")
		{
			 clearInterval(this.shtid);
			 document.title=this.title;
			this.shtid=null;
			 return;
		}
		this.title=document.title;
		var space="  ";
		for(var i=0;i<msg.length;i++)
		{
			space=space+"  ";
		}
		var n=0;
		var max=parseInt(ops)||1000;
		var pmd=function()
		{
			if (n % 2 == 0) 
			{   
					document.title = "【"+msg+"】" + message.title;   
            }else
			{   
					document.title = "【"+space+"】" + message.title; 
            };   
			n++;
			if(n>max)
			{
				clearInterval(message.shtid);
				document.title=message.title;
			}
		}
		this.shtid=setInterval(pmd,600);
	},
	//窗口闪动
	windowShan:function(ops)
	{
		clearInterval(this.wstid);
		if(ops=="stop")
		{
			 clearInterval(this.wstid);
			 return;
		}
		var n=0;
		var max=parseInt(ops)||20;
		var pmd=function()
		{
			if (n % 2 == 0) 
			{   
					window.moveBy(5,0); 
            }else
			{   
					window.moveBy(-5,0);
            };   
			n++;
			if(n>max)
			{
				clearInterval(message.wstid);
			}
		}
		this.wstid=setInterval(pmd,200);
	},	//桌面通知权限
	noticeinit:function()
	{
		if(window.webkitNotifications)
		{
			if (window.webkitNotifications.checkPermission() != 0) 
			{
				console.log("chrome 桌面通知请求");
				window.webkitNotifications.requestPermission();
			}
			 
		}else if (window.Notification && Notification.permission !== "granted") 
		{
			Notification.requestPermission(function (status) 
			{
			  if (Notification.permission !== status) 
			  {
				Notification.permission = status;
			  }
			});
		}else
		{
			//ie
			//注入vbscript	
			if(!this.ieinjur)
			{
			var d=document.createElement("script");	
			d.type="text/vbscript";
			d.text ="Function noticeie(title,body) MsgBox body,64,title  End Function";
			var head = document.getElementsByTagName("head")[0] ||document.documentElement;
			head.appendChild(d);
			this.ieinjur=true;	
			}			
		}
	},
	//桌面通知
	notice:function(title,msg,icon)
	{
		if(window.webkitNotifications)
		{
			if(window.webkitNotifications.checkPermission() != 0)
			{
				message.noticeinit();
			}
			else
			{
				console.log("webkit 通知");
				var n = webkitNotifications.createNotification(icon,title, msg);
				n.show();
				n.ondisplay = function() { };   
				n.onclose = function() { };  
				var cancle=function(){n.cancle};
				setTimeout(cancle, 5000); 
			}
 
		}		
		else if (window.Notification) 
		{
			if(Notification.permission == "granted")
			{
				console.log("firefox 通知");
				var n = new Notification(title,{ icon:icon,body:msg});
			}else
			{
				message.noticeinit();
			}	
		}else//ie
		{
			try
			{
			noticeie(title,msg);
			}catch(ee)
			{
			}
	
		}
	}
}
message.noticeinit();

 

 

测试通过ie7、firefox 24、chrome 32.0.1700.6 Aura

1.播放声音ie使用EMBED标签、其他使用html5的audio标签

2.桌面通知chrome虽然实现了Notification 但似乎没有效果,并且使用Notification.requestPermission会导致浏览器崩溃,所以只能使用自家的webkitNotifications,另外需注意的是webkitNotifications.requestPermission()需要手动触发

 

document.onclick=function(){message.noticeinit()};

firefox实现桌面通知就比较简单了,参照html5 的桌面通知就行了

3.ie可以使用vbscript 的msgbox模拟桌面通知,因为msgbox会是系统重新对焦在ie浏览器上

 

 

效果图

chrome

firefox
 

 ie7



 

  • 大小: 44.4 KB
  • 大小: 6.7 KB
  • 大小: 9.4 KB
分享到:
评论

相关推荐

    在线预览PDF(无需任何插件) 支持IE/Firefox/Coogle

    本解决方案特别强调了对IE、Firefox和Chrome浏览器的支持,这涵盖了大部分用户常用的网络浏览器。 在线预览PDF的技术实现主要基于以下几个关键点: 1. **PDF.js**:这是一个由Mozilla开发的开源库,它允许在Web...

    Firefox火狐浏览器官方52.0.1-win32版本exe安装包

    《Firefox火狐浏览器52.0.1-win32版本:深入解析与使用指南》 Firefox火狐浏览器,由Mozilla基金会开发,是一款全球知名的开源网络浏览器。本文将围绕"Firefox火狐浏览器官方52.0.1-win32版本exe安装包"进行详细...

    iScroll支持IE8+,FIREFOX,CHROME

    它在手机触屏设备上表现出色,同时也兼容桌面浏览器,包括IE8及更高版本,Firefox和Chrome。iscroll的核心功能是提供高性能、低内存占用的滚动解决方案,适用于各种网页组件,如滚动列表、轮播图等。 **iscroll的...

    js实现ctrl+v粘贴上传图片(兼容chrome、firefox、ie11)

    我们或多或少都使用过各式各样的富文本编辑器,其中有一个很方便功能,复制一张图片然后粘贴进文本框,这张图片就被上传了,那么这个方便的功能是如何实现的呢? 原理分析 提取操作:复制=&gt;粘贴=&gt;上传 在这个操作...

    兼容ie,firefox,google等多浏览器的日历控件

    本知识点主要聚焦于一个兼容IE、Firefox、Google等多浏览器的日历控件的实现,这在跨平台、跨设备的网页应用中尤为重要。 1. **浏览器兼容性**: - Internet Explorer (IE):尽管IE的市场份额已经显著下降,但仍有...

    html5桌面通知知识点分享

    2. **兼容性**:支持的浏览器包括IE14+(Edge)、Firefox46+、Chrome29+、Safari9.1+以及Opera38+。 要使用HTML5 Web Notification API,首先需要获取用户的权限。可以通过`Notification.requestPermission()`方法...

    基于EasyUI实现windows桌面

    随着Internet Explorer市场份额的下降,现代浏览器如Chrome、Firefox、Safari和Edge已成为主流。EasyUI通过使用现代浏览器支持的CSS3和HTML5特性,以及良好的浏览器兼容性策略,确保了在这些浏览器上的良好运行。 ...

    跨浏览器的桌面通知插件Push.js.zip

    这个通知API允许在当下流行的浏览器上使用,像Chrome, Safari, Firefox,和IE 9 。可以推送一个通知到用户桌面。如果用户的浏览器不支持这个新的API,会回滚到使用旧的实现方式。运行效果:示例代码:创建通知Push....

    gwt-firefox-winX86IE--plugin.rar

    标题中的“gwt-firefox-winX86IE--plugin.rar”指的是一个针对Google Web Toolkit (GWT) 的Firefox和Windows x86系统上的Internet Explorer浏览器的调试插件压缩包。这个压缩包包含了开发者用于测试和调试GWT应用...

    海康威视 视频WEB插件 含最新版测试demo

    提供适用于Windows桌面操作系统IE、Chrome、Firefox浏览器的实时视频预览和录像回放功能,支持32/64位Chrome、Firefox、IE11浏览器,支持32位IE10浏览器(兼容64位IE10)。

    Chrome 称霸浏览器市场 火狐跌至第四

    根据TheNextWeb的报道,来自Shareaholic统计数据显示,Chrome 依然统治着桌面和移动平台,火狐市场份额已经由第二位滑落至第四位,排名Safari和IE之后。 报告还显示,只有内置于应用的Safari浏览器和Android自带...

    完美兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面js代码

    主要针对IE、Chrome和Firefox这三种常见的浏览器。下面将详细解释每个功能的实现方式。 1. **设为首页**: 这个功能通过`SetHome`函数实现。它首先尝试使用`style.behavior`属性来模拟一个IE特有的行为,即`url(#...

    火狐和谷歌支持ocx

    5. **使用虚拟机或远程桌面**:在某些情况下,如果无法直接在Firefox或Chrome上支持OCX,可以通过在虚拟机或远程桌面中运行IE来访问需要OCX的应用。 在实际操作中,用户应按照“安装插件详细步骤.txt”和“注册ocx...

    C# 获取MAC地址 硬盘ID IE火狐谷歌 带运行库

    if (ieUserAgent.Contains("Firefox")) { // 处理火狐浏览器信息 } else if (ieUserAgent.Contains("Chrome")) { // 处理谷歌浏览器信息 } ``` 描述中提到的"点击HTML界面既有安装过程"可能是指通过HTML页面触发...

    Web桌面应用框架 HoorayOS v2.0 开源免费版.rar

    兼容:IE8 、Firefox、Chrome、Safari、Opera。为实现最优体验,2.0开始不对IE6、7进行兼容,若使用IE6、7访问, 将会看到升级提示。 特色功能概要 多款皮肤 除了自带了5款皮肤可供选择之外,还可按照皮肤编写...

    eWebEditor编辑器JSP版-兼容IE,火狐及360等浏览器真正可用版

    2. **兼容性强**:不仅兼容IE、Firefox、360等常见浏览器,还支持Chrome、Safari等其他主流浏览器,确保了广泛的用户覆盖。 3. **易于集成**:通过简单的API调用,可以轻松地将eWebEditor集成到任何JSP应用中,无论...

    IE版本模拟器(简体中文)

    在IT行业中,尤其是在Web开发领域,确保应用程序在各种浏览器和不同...尽管现代浏览器如Chrome、Firefox和Edge已逐渐取代IE,但考虑到企业环境和旧版系统的存在,对IE兼容性的测试仍然是Web开发过程中不可或缺的一环。

    IE8

    然而,随着技术的不断发展,现代浏览器如Chrome、Firefox和Edge等提供了更多的功能和更好的性能,IE8逐渐被取代。对于仍在使用IE8的用户,建议考虑升级到更安全、更现代化的浏览器以获取更好的网络体验。

    Web视频播放——VLC插件

    其次,为了确保跨浏览器兼容性,可能需要为不同的浏览器(如Firefox、Chrome)提供相应的插件版本或备选方案。最后,考虑到性能和加载速度,优化视频源的编码和传输方式也是必要的。 在提供的压缩包文件"VlcTest"中...

    Win7系统从IE9恢复到IE8

    3. 若仍有问题,建议检查网络设置或尝试其他解决方案,例如安装第三方浏览器如Chrome或Firefox等。 通过以上步骤,用户可以在Win7系统中轻松地从IE9恢复到IE8,解决因兼容性问题导致的无法播放Flash动画或视频等...

Global site tag (gtag.js) - Google Analytics