天天看點

關于判斷是否安裝flash

//是否安裝了flash
function flashChecker() {
var hasFlash = 0; //是否安裝了flash
var flashVersion = 0; //flash版本
if (document.all) {
var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
if (swf) {
hasFlash = 1;
VSwf = swf.GetVariable("$version");
flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
}
} else {
if (navigator.plugins && navigator.plugins.length > 0) {
var swf = navigator.plugins["Shockwave Flash"];
if (swf) {
hasFlash = 1;
var words = swf.description.split(" ");
for (var i = 0; i < words.length; ++i) {
if (isNaN(parseInt(words[i]))) continue;
flashVersion = parseInt(words[i]);
}
}
}
}
return { f: hasFlash, v: flashVersion };
}
var isSafari = /Safari/.test(navigator.userAgent)// Safari浏覽器
var oScriptFirst = document.getElementsByTagName('script')[0];//頁面中第一個script标簽
var newScript = document.createElement('script');//建立一個script标簽
if(isSafari){
newScript.src=videojsURL;//設定src
var ovideo = document.getElementById('example-video');//擷取video标簽
var osource =ovideo.getElementsByTagName('source')[0];
osource.setAttribute('src',om3u8);
}else{
if(!flashChecker().f){
var str = '您沒有安裝flash請下載下傳安裝<a target="_blank" href="https://get2.adobe.com/cn/flashplayer/" target="_blank" rel="external nofollow" style="color:#c90000">點選下載下傳</a>';
$("#video_box").html(str).attr("style","line-height: 400px;text-align: center;font-size: 16px;");
}else{
var videoObject = {
container: '#video_box',//“#”代表容器的ID,“.”或“”代表容器的class
variable: 'player',//該屬性必需設定,值等于下面的new chplayer()的對象
autoplay:true,
live:false,//直播為true;時移false
poster:my_pic,
video:om3u8//視訊位址
};
var player=new ckplayer(videoObject);
}
}
oScriptFirst.parentNode.insertBefore(newScript,oScriptFirst);//videojs插入第一個script元素之前
newScript.onload = function(){//js加載完畢調用初始化
if(isSafari){
videojs('example-video',{
controls: true,//是否控制條
autoplay: true,//自動播放
preload: 'auto'//預加載
},function(){
this.on('playing', function() {
ovideo.muted = false;
});
});
}
};