gpt4 book ai didi

javascript - window.onload 导致我的 javascript 代码出现问题

转载 作者:行者123 更新时间:2023-11-30 15:22:40 25 4
gpt4 key购买 nike

有一个广告代码导致我的 javascript 代码出现问题,当我与他们的支持团队交谈时,他们告诉我不要使用 window.onload

这是他们的重播

Just don't use window.onload. Better get familiar with addEventListener / attachEvent. The onload can be (and possibly is) overwritten by our adcode.

那么在这种情况下我应该使用什么来使我的代码工作而不是 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;
}

最佳答案

您好!

DOMContentLoaded 事件将是要走的路

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

希望我的回答能解决您的问题!

关于javascript - window.onload 导致我的 javascript 代码出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43459458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com