[英]Google web app not running Javascript script
Allright I have a problem, I am trying to make a google chrome app and ive got the basics working, what I have is a html file that loads another html file inside of it, the html file that is loads runs a script that displays the time. 好吧,我有一个问题,我正在尝试制作一个Google chrome应用程序,并且ive有了基本功能,我所拥有的是一个html文件,该文件在其中加载了另一个html文件,正在加载的html文件运行了一个脚本,该脚本显示了时间。 When I run it in my web browser it works fine, but when I run it via google chrome as an actual app the time doesn't show up, heres my code.
当我在网络浏览器中运行它时,它工作正常,但是当我通过google chrome作为实际应用程序运行它时,时间却没有显示,这是我的代码。
The file that the chrome app runs: 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>
And the menu.html file that 'should display the time' 还有“应该显示时间”的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>
If anyone knows how to get the time to show up I would greatly appreciate it :D 如果有人知道如何花时间露面,我将不胜感激:D
Move your script into it's own file, eg. 将脚本移动到它自己的文件中,例如。
menu.js
, and at the bottom add: menu.js
,并在底部添加:
document.addEventListener('DOMContentLoaded', function () {
startTime();
});
Then in your menu.html, just add this to the head. 然后在您的menu.html中,只需将其添加到头部即可。
<script type="text/javascript" src="menu.js"></script>
I'm more than sure it's the Content Security Policy (CSP) that's preventing the inline onload event to not trigger. 我非常确定是内容安全策略(CSP)阻止了内联onload事件不触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.