Javascript实例教程(4-1)

利用Javascript探测网络浏览器的插件程序

利用Javascript可以探测在网络浏览器中的插件程序,但是值得指出的是否,它只在Netscape Navigator有效。下面的代码显示了怎样探测audio/midi类型插件程序:

  1<script language="JavaScript"><!-- 
  2
  3  
  4
  5
  6var can_play = false; 
  7
  8  
  9
 10
 11  
 12  
 13var mimetype = 'audio/midi'; 
 14
 15  
 16
 17
 18  
 19  
 20if (navigator.mimeTypes) { 
 21
 22  
 23
 24
 25if (navigator.mimeTypes[mimetype] != null) { 
 26
 27  
 28
 29
 30if (navigator.mimeTypes[mimetype] 
 31
 32  
 33
 34
 35.enabledPlugin != null) { 
 36
 37  
 38
 39
 40can_play = true; 
 41
 42  
 43
 44
 45document.write('<EMBED SRC="sound.mid" 
 46
 47  
 48
 49
 50HIDDEN=TRUE LOOP=FALSE AUTOSTART=FALSE>'); 
 51
 52  
 53
 54
 55} 
 56
 57  
 58
 59
 60} 
 61
 62  
 63
 64
 65} 
 66
 67  
 68
 69
 70  
 71  
 72function playSound() { 
 73
 74  
 75
 76
 77if (document.embeds && can_play) { 
 78
 79  
 80
 81
 82if (navigator.appName == 'Netscape') 
 83
 84  
 85
 86
 87document.embeds[0].play(); 
 88
 89  
 90
 91
 92else 
 93
 94  
 95
 96
 97document.embeds[0].run(); 
 98
 99  
100
101
102} 
103
104  
105
106
107} 
108
109  
110
111
112  
113  
114function stopSound() { 
115
116  
117
118
119if (document.embeds && can_play) 
120
121  
122
123
124document.embeds[0].stop(); 
125
126  
127
128
129} 
130
131  
132
133
134//--></script>

那在网页上如何调用呢?以下是具体代码:

1<a href="#" onmouseout="stopSound()" onmouseover="playSound()"><img border="0" height="100" src="image.gif" width="100"/></a>
Published At
Categories with 网页设计
comments powered by Disqus