[英]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下面是 popup.html 页面的代码 我使用的是http://code.google.com/chrome/extensions/getstarted.ZFC35FDC70D5FC69D269EZ883A822C7A53给出的 hello world 示例
<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 sa blank popup... what am I doing wrong?但是我得到的只是一个空白弹出窗口......我做错了什么? What needs to be done in order to show my javascript?
为了显示我的 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.