I'm new here so if you see anything off about my question or 'etiquette' please let me know!
I'm trying to create a personalized new tab extension in Google Chrome, and have a problem with JavaScript time code appearing. Though it works in Brackets, the compiler I use, the time never displays whenever I load the extension folder onto Chrome. After searching around, I learned that this was because I had my Javascript inline rather than in an external file, and so I naturally attempted to move my script into a time.js file. I am not totally sure about how to show the time upon the new tab loading, but I thought I'd show y'all my attempts.
My index.html file, disregarding irrelevant code, shows as:
<html>
<head>
<title>New Tab</title>
<script type = "text/javascript" src = "time.js"></script>
</head>
<body onload = "startTime()">
<div id = "time"></div>
</div>
</body>
^ Can't see closing html tag for some reason. Anyway, here is my time.js file, using some changed up w3school code:
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
h = minusTwelve(h);
m = checkTime(m);
document.getElementById('time').innerHTML =
h + ":" + m;
var t = setTimeout(startTime, 500);}
function minusTwelve(i) {
if (i > 12) {i = i - 12};
if (i == 0) {i = 12};
return i;
function minusTwelve(i) {
if (i > 12) {i = i - 12};
if (i == 0) {i = 12};
return i;}
function checkTime(i) {
if (i < 10) {i = "0" + i};
return i;}
(sorry about the indents in those last two functions, something went weirdly :P)
Anyway, I have this so far and I am not sure how to integrate the time when the tab loads in Chrome. I have seen some people mention addEventListener or something for clicks and whatnot, but I am not sure how this would apply here. Also, in the body of my HTML is the onload call, and though I would think this would take care of it, it seems to not have :/. I would really appreciate your help.
Thanks!