onload does not work with setTimeout

0

I am trying to organize this script according to my need, the thing is that I need the script to load only when the whole page loads and for this we have the onload .. good, but when I enter the onload does not work. .. another question, I'm trying to make the Facebook button appear at the end of the count in case the code will show the 00 but I would like to insert an iframe I tried to insert somehow however without success. Taking advantage of the opportunity if someone can explain to me why the count starts at 2 instead of the determined 3.

This is the code I'm working on: link

    
asked by anonymous 28.02.2017 / 20:41

1 answer

1

In this code I was able to put the tan and iframe button

	var start = new Date();
	start = Date.parse(start)/1000;
	var seconds = 3; // TEMPO EM SEGUNDOS EM QUE HAVERÁ O REDIRECIONAMENTO
	function CountDown(){
	    var now = new Date();
	    now = Date.parse(now)/1000;
	    var counter = parseInt(seconds-(now-start),10);
	    if(counter <= 9){
		    document.getElementById('countdown').innerHTML = ' 0'+counter;
	    }else{
		    document.getElementById('countdown').innerHTML = counter;
	    }
	    if(counter > 0){
	        timerID = setTimeout("CountDown()", 100)
	    }else{
			document.getElementById('countdown').innerHTML = '<iframe src="https://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&width=450&layout=standard&action=like&show_faces=true&share=true&height=80&appId"width="450" height="80" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe><br><iframe id="iframe_color_names" name="iframe_color_names" src="http://kithomepage.com/cores/iframe_color_name.php"width="860" height="600" frameborder="0" allowtransparency="true" scrolling="no"></iframe>';
		}
	}
	window.setTimeout('CountDown()',100);
<span id="countdown">3</span>
    
01.03.2017 / 00:31