Blank popup when using onload() function in javascript with Google Chrome Extension development
Below is the code for popup.html page I am using the hello world example given at http://code.google.com/chrome/extensions/getstarted.html
<html>
<head><title>Update Time</title>
<script>
function UpdateTime(){
var today = new Date();
var hour = today.getHours();
var mins = today.getMinutes();
var secs = today.getSeconds();
if (secs <=9){
secs 开发者_运维百科= "0" + secs
}
var TotalTime = hour + ":" + mins + ":" + secs;
if (document.layers) {
document.layers.time.document.write(TotalTime);
document.layers.time.document.close();
}else if (document.all) {
time.innerHTML = TotalTime;
}
setTimeout("UpdateTime()", 1000)
}
</script>
</head>
<body onload="UpdateTime()">
<span id=time style="position:absolute;"></span>
</body>
</html>
But all I am getting s a blank popup... what am I doing wrong? What needs to be done in order to show my javascript?
Instead of:
if (document.layers) {
document.layers.time.document.write(TotalTime);
document.layers.time.document.close();
}else if (document.all) {
time.innerHTML = TotalTime;
}
Do:
document.getElementById("time").innerHTML = TotalTime;
精彩评论