检测浏览器是否支持WMP(Windows Media Player)

最近群里有朋友提到用WMP插件做网页mp3播放器,在使用时需要检查浏览器是否支持WMP;WMP的支持,IE下是用ActiveX,其它浏览器一般是用插件。闲暇查了一下相关资料,写了下面的检测代码,支持所有主流浏览器:


<script language="text/javascript">
function testForWmp() {
var player;
var plugin;

/**
* 检查是否支持ActiveX
*
* 如果支持,就尝试是否创建wmp播放器成功;创建成功则为支持,创建失败则为不支持
*/
try{
if(window.ActiveXObject) {
player = new ActiveXObject("WMPlayer.OCX.7");
} else if (window.GeckoActiveXObject){
player = new GeckoActiveXObject("WMPlayer.OCX.7");
}
}catch(oError) { }

/**
* 检查是否支持Windows Media Player Plugin
*
* 如果支持,就尝试是否创建wmp播放器成功;创建成功则为支持,创建失败则为不支持
*/
try{
if(navigator.mimeTypes) {
plugin = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin;
}
}catch (oError) {}

//测试用的输出,可以删除
var message = "Windows Media Player ActiveX:"+ (player ? "支持" : "不支持") + "n";
message += "Windows Media Player Plugin:"+ (plugin ? "支持" : "不支持") + "n";
alert(message);

//返回结果 true/false
if(player || plugin)
return true;
else
return false;
}

</script>



( ! ) Warning: Missing argument 1 for cwppos_show_review(), called in /data/www/enjoyphp/wp-content/themes/flat/content-single.php on line 29 and defined in /data/www/enjoyphp/wp-content/plugins/wp-product-review/includes/legacy.php on line 18
Call Stack
#TimeMemoryFunctionLocation
10.0000354824{main}( ).../index.php:0
20.0001355112require( '/data/www/enjoyphp/wp-blog-header.php' ).../index.php:17
30.168610162128require_once( '/data/www/enjoyphp/wp-includes/template-loader.php' ).../wp-blog-header.php:19
40.169810233272include( '/data/www/enjoyphp/wp-content/themes/flat/single.php' ).../template-loader.php:74
50.256510792880get_template_part( ).../single.php:5
60.256510793400locate_template( ).../general-template.php:167
70.256510793496load_template( ).../template.php:643
80.256510793880require( '/data/www/enjoyphp/wp-content/themes/flat/content-single.php' ).../template.php:686
90.261810778992cwppos_show_review( ).../content-single.php:29

发表评论

电子邮件地址不会被公开。 必填项已用*标注