Blank popup when using onload() function in javascript with Google Chrome Extension development
966
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;
Related videos on Youtube
Author by
Gaurav N
Updated on November 20, 2022Comments
-
Gaurav N over 1 year
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?