好吧我有一个问题,我正在尝试制作一个谷歌浏览器应用程序,我已经得到了基础工作,我有一个html文件加载其中的另一个html文件,加载的html文件运行脚本显示时间。当我在我的网络浏览器中运行它时工作正常,但当我通过谷歌浏览器作为一个实际的应用程序运行时,时间不会显示,继承我的代码。
Chrome应用运行的文件:
<!DOCTYPE html>
<html>
<head>
<title>GimOS Emulator</title>
</head>
<body bgcolor = black>
<center><font color="white">System Type: Emulated Mobile System (EMS) </font> </center>
<center><IMG SRC = "Gimijes.png"><center>
<iframe src="menu.html" width=200 height=440></iframe>
</body>
</html>
以及'应该显示时间'的menu.html文件
<!DOCTYPE html>
<html>
<head>
<title>GimOS Emulator</title>
</head>
<body bgcolor = white>
<center><script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500);
}
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div></center>
</body>
</html>
如果有人知道如何有时间出现,我会非常感激:D
答案 0 :(得分:0)
将脚本移动到自己的文件中,例如。 menu.js
,在底部添加:
document.addEventListener('DOMContentLoaded', function () {
startTime();
});
然后在你的menu.html中,只需将其添加到头部。
<script type="text/javascript" src="menu.js"></script>
我更确定内容安全策略(CSP)阻止内联onload事件不会触发。