简体   繁体   English

Google Web应用程序未运行Javascript脚本

[英]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.

相关问题 运行Google Script Web应用程序后关闭窗口? - Closing window after running a Google Script web app? 运行 Google web 应用脚本后出现黑屏 - Getting blank screen after running Google web app script JavaScript addEventListeners 未从 web 应用程序的脚本文件运行 - JavaScript addEventListeners not running from script file for web app JavaScript onScroll无法在Google Apps脚本网络应用中使用 - JavaScript onScroll not working in Google Apps Script web app google app脚本javascript - google app script javascript Google App Script网络应用程序的局限性 - Limitation of Google App Script web app 为什么Javascript Google docs应用脚本try语句仅运行一条语句,如果 - why is Javascript google docs app script try statement running only one statement if Google Apps Script Web App serverHandler输出中缺少嵌入式Javascript - Embedded Javascript missing from Google Apps Script Web App serverHandler output 对具有 JavaScript、HTML、Google Apps 脚本的 web 应用程序进行故障排除的最佳方法是什么? - What is the best way to troubleshoot an web app having JavaScript, HTML, Google Apps Script? “如何在 javascript 中获取 google apps 脚本 web 应用沙箱的 url 查询字符串参数? - "How can I get the url query string parameters of a google apps script web app sandbox in javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM