I am trying make a header same as attached image. First logo image on the left side of the header and side to it a date and time displayed. I have written below code in google app script and publish as a web application. But image is not loading and also date is displayed with time zone.
const today = Date();
document.getElementById('date').innerHTML=today;
.heading {
font-size: 30px;
font-weight: bold;
background-color:#9a9999;
text-align: center;
width: 100%;
height: 100px;
float: left;
}
.date {
float: left;
}
img {
height: 40px;
width: 40px;
float: left;
position: center;
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<base target="_top">
</head>
<body>
<div class="heading">
<img src="https://drive.google.com/uc?export=download&id=1JP06az8YEfm0CMnPgkahaponh71iTk_X">
<div class="date" id="date"></div>
<div>Sample header</div>
</div>
</body>
</html>
2
Answers
I assume you have already achieved to publish your script as web app so I will not write how to.
for the correction of your date problem is simple but playing with date is not really simple sometimes. it needs to be formatted to serve your needs.
so, lets write the code first, then the explanation..
we get the date, then separate the year, month and day out of the day object.
padStart function adds the leading zero to our dates.
then we gather all as a string…
now you can safely write it to html
one more thing as you may realize, I have put all the code inside onload function to ensure that they will be working after DOM is fully loaded, otherwise there may be a problem to assign values of our results.
and for the image, I don’t understand what kind of image you are trying to load from this url but, if you test it with a proper image, you will see its loading. so no problem on that, apart from the url may be…
you may try something like,
hope it helps.
Use
thumbnail
instead ofexport
This URL =
https://drive.google.com/thumbnail?id=FILE_ID&sz=400
is a thumbnail-sized image for a specific Google Drive file, where FILE_ID is the unique ID of the file in Google Drive. and for this URL =https://drive.google.com/us?export=view&id=FILE_ID
provides a direct link to view the file in Google Drive, where FILE_ID is again the unique file ID.Note: To ensure the thumbnail or direct link works for everyone, make sure the file’s sharing settings are set to "Anyone with the link can view."
Script used
Code.gs
Index.html
Note: Adjust the CSS base on your design.
Sample Output