在 10 秒 javascript 后停止页面加载

Stop page load after 10 sec javascript

本文关键字:加载 javascript      更新时间:2023-09-26

我遇到了一个问题,在我的网站上我正在使用

    <script type="text/javascript">
    window.onload = function() {
        var countdownElement = document.getElementById('countdown'),
        downloadButton = document.getElementById('new_download'),
        seconds = 10 ,
        second = 0,
        interval;
        downloadButton.style.display = 'none';
        interval = setInterval(function() {
            if (second >= seconds) {
                downloadButton.style.display = 'block';
                countdownElement.style.display = 'none';
                clearInterval(interval);
            }
            second++;
        }, 1000);
    }
</script>

但是一些谷歌广告继续加载,这个功能不起作用。 所以我想在页面页脚使用此脚本在 10 秒后停止页面加载

<script type="text/javascript">
     setTimeout( function(){ 
    window.stop() 
  }  , 10000 );
    </script>

但这不起作用,有什么方法可以在一段时间后停止页面加载或从页面加载时间或除window.onload功能之外的其他方法跳过谷歌广告加载时间

这是我写的一个对我有用的快速 jquery 代码......虽然我没有谷歌广告。我摆脱了setInterval() 希望对您有所帮助。

$("document").ready(function() {
$("#new_download").css({
"display":"none"
});
setTimeout(displaydbutton,10000);
} 
function displaydbutton(){
$("#dload").css({
"display":"block"
});
clearTimeout();
});