2017-04-17 29 views
1

存在是造成问题,我的JavaScript代码的广告代码,当我跟他们的支持团队,他们告诉我,不使用window.onload在window.onload造成问题,我的javascript代码

这里是他们的重播

只是不要使用window.onload。最好熟悉 addEventListener/attachEvent。 onload可以是(可能是) 被我们的地址覆盖。

那么我应该在这种情况下使用我的代码而不是window.onload?

这里是我的全部javascript代码,包括window.onload

function startChecking() { 
    secondsleft -= 1e3, document.querySelector(".load_vid").innerHTML = "Please Wait.. " + Math.abs(secondsleft/1e3) + " Seconds", 0 == secondsleft && (clearInterval(interval), $(".reloadframe").show() + $(".share").show(), document.querySelector(".load_vid").style.display = "none"/*, document.querySelector(".frame_src").style.display = "", document.querySelector(".frame_src").src = document.querySelector(".frame_src").getAttribute("data-src"), $("#btn_play_s").hide()*/,$("#btn_play_s").show()) 
} 

function startschedule() { 
    document.querySelector(".frame_src").src = "about:blank", clearInterval(interval), secondsleft = threshold, document.querySelector(".load_vid").innerHTML = "Please Wait.. " + Math.abs(secondsleft/1e3) + " Seconds", interval = setInterval(function() { 
     startChecking() 
    }, 1e3) 
} 

function resetTimer() { 
    startschedule() 
} 
var timeout, interval, threshold = 1e4, 
    secondsleft = threshold; 
window.onload = function() { 
    $("#btn_play_s").hide() 
    startschedule() 
}; 

$(function(){$(".vid_link").on("click",function(){$(this).toggleClass("vid_link_selc").siblings().removeClass("vid_link_selc")})}); 

function reloadthis() { 
    var ifr = document.getElementsByName('right')[0]; 
    ifr.src = ifr.src; 
} 
+0

你试过addEventListener了吗? – Kobbe

回答

1

您好!

DOMContentLoaded事件是去

document.addEventListener("DOMContentLoaded", function(){ 
    //TODO WHEN PAGE LOADED 
     } 
    ); 

希望我的回答可以解决你的问题的方式!

+0

谢谢亲爱的。这解决了我的问题,等待几分钟,我会接受你的回答 –

1

这应该适合你。

document.onreadystatechange = function() { 
    if (document.readyState == "interactive") { 
     $("#btn_play_s").hide(); 
     startschedule(); 
    } 
} 
+0

感谢您的时间亲爱的。但托马斯是解决它的答案。再次感谢 –

+0

不客气。很高兴你的问题解决了。 –