-1

I am facing a problem, on my website i am using

    <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>

But some google ads keep on loading and this function don't work. so i thought to stop page load after 10 sec with this script in footer of page

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

But this is not working, is there any way i can stop page load after some time or skip google ads load time from page load time or other method except window.onload function

Harinder
  • 1,257
  • 8
  • 27
  • 54
  • 3
    ... You have Google ads on your website... that you want to block? – Madara's Ghost Feb 14 '16 at 15:19
  • You could ruin users with slow data connection with that script.. – Shrikantha Budya Feb 14 '16 at 15:19
  • @MadaraUchiha No i want them to stop load after 10 sec ... some ads load for ever. – Harinder Feb 14 '16 at 15:20
  • Related: [Stopping a iframe from loading a page using javascript](http://stackoverflow.com/questions/2207501/stopping-a-iframe-from-loading-a-page-using-javascript). Second answer demonstrates using window.stop() with setTimeout(). – Yogi Feb 14 '16 at 15:57

1 Answers1

0

Heres a quick jquery code i wrote which worked for me...although i had no google ads. and i got rid of the setInterval() hope it helps..

$("document").ready(function() {
$("#new_download").css({
"display":"none"
});
setTimeout(displaydbutton,10000);
} 
function displaydbutton(){
$("#dload").css({
"display":"block"
});
clearTimeout();
});
Shrikantha Budya
  • 646
  • 1
  • 4
  • 15