2 dodd001 dodd001 于 2016.02.11 09:48 提问

手机播放器JS判断代码重复的问题

这是西瓜的手机端JS判断代码,现在一个严重的问题就是播放器调用返回到播放页面,第一次的时候又马上调用播放器,再从播放界面退出来就不会
这是代码,大神帮忙分析一下

 document.writeln("<div id=\"xg_box\"></div>");
if(XgPlayer.Second<1){
    XgPlayer.Second=1;
}
var browser;
var installflag=1;
function $XghdInstall(){
    $$("xg_box").style.display="none";
    if(installflag==1){
    document.writeln('<iframe border="0" src="'+XgPlayer.Installpage+'" marginWidth="0" frameSpacing="0" marginHeight="0" frameBorder="0" noResize scrolling="no" width="'+XgPlayer.Width+'" height="'+XgPlayer.Height+'" vspale="0" ></iframe>');
    installflag=0;
    }
}
var AdsBeta6 = {
    'Start': function() {
        $$('buffer').style.display = 'block';
        if(xiguaPlayer.IsBuffing()){
            $$('buffer').height = XgPlayer.Height-80;
        }else{
            $$('buffer').height = XgPlayer.Height-60;
        }
    },
    'End': function() {
        if(!XgPlayer.Second){
            $$('buffer').style.display = 'none';
            $$('xiguaPlayer').style.display = 'block';
            xiguaPlayer.height = XgPlayer.Height;
        }
    },
    'Status' : function() {
        if(xiguaPlayer.IsPlaying()){
            this.End();
        }else{
            this.Start();
        }
    }
}
function $$(id){
    return document.getElementById(id);
}
function $Showhtml(){
     browser = navigator.appName;
    if(browser == "Netscape"|| browser == "Opera"){
        if(/iPad|iPhone/i.test(navigator.userAgent))
        {
            setTimeout($PlayerIOS,1000);
        }
        if(/Android/i.test(navigator.userAgent))
        {
            $PlayerAndroid();
        }
        if(isIE()){
        return $PlayerIe();
        }else{
            return $PlayerNt();
        }
    }else if(browser == "Microsoft Internet Explorer"){
        return $PlayerIe();
    }
    else{
        alert('请使用IE内核浏览器观看本站影片!');
    }   
}
    function isIE() {
        if (!!window.ActiveXObject || "ActiveXObject" in window)  {
            browser = "Microsoft Internet Explorer";
            return true;  
        }
        return false;  
    }  


function installapp(){  
        return function(){  
            var clickedAt = +new Date;      
            setTimeout(function()
            {  
                try{if(isxg()){return;}}catch(e){;}
                  if (+new Date - clickedAt < 1500)
                  {
                    alert("即将为你转到苹果商店下载\"瓜瓜播放器\",安装成功后,重新刷新本页面进行播放");
                    setTimeout(function(){
                        var surl="https://itunes.apple.com/cn/app/gua-gua-bo-fang-qi/id977122011?l=en&mt=8";
                        top.location.href=surl;
                    },3000);
                  } 
            }, 500);
        };  
    }  

function $PlayerIOS(){
    var newurl="#";
    if(typeof(XgPlayer)!='undefined'){
        newurl = XgPlayer['Url'].replace("ftp://","xg://");
    }
    else if(typeof(Player)!='undefined'){
        newurl = Player['Url'].replace("ftp://","xg://");
    }
    var xuanjipage = top.location.href;
    if(typeof(XgPlayer['XuanJiPage'])!='undefined') xuanjipage = XgPlayer['XuanJiPage'];
    if(typeof(XgPlayer['MobiAd'])!='undefined')top.location.href = newurl+"|"+XgPlayer['MobiAd']+"|"+xuanjipage;
    else top.location.href = newurl;
    installapp()();
}



function $PlayerAndroid(){
    var finalurl;
    var newurl="#";
    if(typeof(XgPlayer)!='undefined'){
        newurl = XgPlayer['Url'].replace("ftp://","xg://");
    }
    else if(typeof(Player)!='undefined'){
        newurl = Player['Url'].replace("ftp://","xg://");
    }
    var xuanjipage = top.location.href;
    if(typeof(XgPlayer['XuanJiPage'])!='undefined') xuanjipage = XgPlayer['XuanJiPage'];
    if(typeof(XgPlayer['MobiAd'])!='undefined')finalurl = newurl+"|"+XgPlayer['MobiAd']+"|"+xuanjipage;
    else finalurl = newurl;

    // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为
    // 否则打开a标签的href链接

    var timeout, t = 1000, hasApp = true;  
    setTimeout(function () {  
        if (hasApp) {  
            location.href=finalurl;
        } else {  
            //top.location.href="http://static.xigua.com/xigua_v2.apk";
            top.location.href="http://s2.xiguaplayer.com/xigua_v1.07.apk";
        }  
        document.body.removeChild(ifr);  
    }, 2000)  

    var t1 = Date.now();  
    var ifr = document.createElement("iframe");  
    ifr.setAttribute('src', finalurl);  
    ifr.setAttribute('style', 'display:none');  
    document.body.appendChild(ifr);  
    timeout = setTimeout(function () {  
         var t2 = Date.now();  
         if (!t1 || t2 - t1 < t + 100) {  
             hasApp = false;  
         }  
    }, t);  

}

function $PlayerNt(){
    if (navigator.plugins) {
        var install = true;
        for (var i=0;i<navigator.plugins.length;i++) {
            if(navigator.plugins[i].name == 'XiGua Yingshi Plugin'){
                install = false;break;
            }
        }
        if(!install){
            player = '<div style="width:'+XgPlayer.Width+'px;height:'+XgPlayer.Height+'px;overflow:hidden;position:relative"><iframe src="'+XgPlayer.Buffer+'" scrolling="no" width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0" name="buffer" id="buffer" style="position:absolute;z-index:2;top:0px;left:0px"></iframe><object  width="'+XgPlayer.Width+'" height="'+XgPlayer.Height+'" type="application/xgyingshi-activex" progid="xgax.player.1" param_URL="'+XgPlayer.Url+'" param_NextCacheUrl="'+XgPlayer.NextcacheUrl+'" param_LastWebPage="'+XgPlayer.LastWebPage+'" param_NextWebPage="'+XgPlayer.NextWebPage+'" param_OnPause="onPause" param_OnFirstBufferingStart="onFirstBufferingStart" param_OnFirstBufferingEnd="onFirstBufferingEnd" param_OnPlayBufferingStart="onPlayBufferingStart" param_OnPlayBufferingEnd="onPlayBufferingEnd" param_OnComplete="onComplete" param_Autoplay="1" id="xiguaPlayer" name="xiguaPlayer"></object></div>';
            if(XgPlayer.Second){
                setTimeout("onAdsEnd()",XgPlayer.Second*1000);
            }   
            return player;
        }
    }
    return '<iframe border="0" src="'+XgPlayer.Installpage+'" marginWidth="0" frameSpacing="0" marginHeight="0" frameBorder="0" noResize scrolling="no" width="'+XgPlayer.Width+'" height="'+XgPlayer.Height+'" vspale="0" ></iframe>';
}
function $PlayerIe(){
    playerhtml = '<iframe src="'+XgPlayer.Buffer+'" id="buffer" width="'+XgPlayer.Width+'" height="'+(XgPlayer.Height-80)+'" scrolling="no" frameborder="0" style="position:absolute;z-index:9;"></iframe><object classid="clsid:BEF1C903-057D-435E-8223-8EC337C7D3D0"  style="display:none" width="'+XgPlayer.Width+'" height="'+XgPlayer.Height+'" id="xiguaPlayer" name="xiguaPlayer" onerror="$XghdInstall();"><param name="URL" value="'+XgPlayer.Url+'"/><param name="NextCacheUrl" value="'+XgPlayer.NextcacheUrl+'"><param name="LastWebPage" value="'+XgPlayer.LastWebPage+'"><param name="NextWebPage" value="'+XgPlayer.NextWebPage+'"><param name="OnPlay" value="onPlay"/><param name="OnPause" value="onPause"/><param name="OnFirstBufferingStart" value="onFirstBufferingStart"/><param name="OnFirstBufferingEnd" value="onFirstBufferingEnd"/><param name="OnPlayBufferingStart" value="onPlayBufferingStart"/><param name="OnPlayBufferingEnd" value="onPlayBufferingEnd"/><param name="OnComplete" value="onComplete"/><param name="Autoplay" value="1"/></object>';
    return playerhtml;
}
function $PlayerIeBack(){
    if(browser == "Microsoft Internet Explorer"){
        if(xiguaPlayer.URL != undefined){
            if(XgPlayer.Second){
                setTimeout("onAdsEnd()",XgPlayer.Second*1000);
            }   
        }
xiguaPlayer.ConfigurePlayer('url', XgPlayer.Url);
    }
}
//beta7版播放器回调函数
var onPlay = function(){
    $$('buffer').style.display = 'none';
    //强制缓冲广告倒计时
    if(XgPlayer.Second&&xiguaPlayer.IsPlaying()){
        xiguaPlayer.Play();
    }
}
var onPause = function(){
    $$('buffer').height = XgPlayer.Height-63;
    $$('buffer').style.display = 'block';
}
var onFirstBufferingStart = function(){
    $$('buffer').height = Player.Height-80;
    $$('buffer').style.display = 'block';
}
var onFirstBufferingEnd = function(){
    if(XgPlayer.Second){
        xiguaPlayer.Play();
    }else{
        $$('buffer').style.display = 'none';
    }
}
var onPlayBufferingStart = function(){
    $$('buffer').height = XgPlayer.Height-80;
    $$('buffer').style.display = 'block';
}
var onPlayBufferingEnd = function(){
    $$('buffer').style.display = 'none';
}
var onComplete = function(){
    onPause();
}
var onAdsEnd = function(){
    XgPlayer.Second = 0;
    $$('buffer').style.display = 'none';
    xiguaPlayer.style.display = 'block';
    setInterval("adshow()",1000);
}
  function adshow(){
      if(xiguaPlayer.IsPlaying()){
        $$('buffer').style.display = 'none';
      }else if(xiguaPlayer.IsBuffing()){
        $$('buffer').height = XgPlayer.Height-63;
        $$('buffer').style.display = 'block';
      }else if(xiguaPlayer.IsPause()){
        $$('buffer').height = XgPlayer.Height-63;
        $$('buffer').style.display = 'block';
      }else{
        $$('buffer').height = XgPlayer.Height-63;
        $$('buffer').style.display = 'block';
      }
  }
var install = true;
playerhtml=$Showhtml();
$$("xg_box").innerHTML=playerhtml;
$PlayerIeBack();

2个回答

devmiao
devmiao   Ds   Rxr 2016.02.12 05:19
dodd001
dodd001   2016.02.11 09:50

这里是示例网站 www.xss666.com 如果不大明白我的意思,可以进去观看体验一下

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!