I have a page that uses modernizr.js which runs when the page loads up. Before I added this I had a simple js clock script running to display the time which also loaded when the page loaded, however, since adding both of them to the page at the same time makes one or the other stop working.
I am still fairly new to javascript and am getting to grips with the rules (self taught). Is it possible to ave two scripts running on load and if so how? Or, am I barking up the wrong tree and if so is there something wrong with my code?
This is what I had…
<script>
window.onload = function() {
if(window.FileReader && Modernizr.draganddrop){
window.location = "http://www.dentaldigs.co.uk/image_upload.php"
}
};
</script>
<script>
// add a zero in front of numbers<10
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
function clock()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
m=checkTime(m);
s=checkTime(s);
document.getElementById('clock_div').innerHTML=h+":"+m+":"+s;
t=setTimeout(function(){clock()},500);
}
</script>
<body onLoad="clock()">
</body>
With the clock script in place the modernizr.js doesn’t work.
Thanks
Why don’t you simply add
clock();towindow.onloadright after calling the Modernizr script: