ReferenceError: "document" is not defined

Bruno Estrazulas picture Bruno Estrazulas · Nov 25, 2012 · Viewed 17.5k times · Source

Im new to JavaScript and even more new to Google Apps Script. Im trying a simple function that shows the current date (only day, month e and full year), but the Google Script show the error ReferenceError: "document" is not defined.

My goal is to use this function in a Google Site. Here is the code:

function Data()
{
var d=new Date();
var dia=d.getDate();
var mes=d.getMonth();
var ano=d.getFullYear();
var DataCompleta=dia + "/" + mes + "/" + ano
document.write(DataCompleta);
}

Answer

Quentin picture Quentin · Nov 25, 2012

Code running as a Google Apps Script does not run in the browser, so you cannot use web browser APIs with it. If you want to output content to a Google Site, then you need to use the API for Sites.

Presumably you would want something like createWebPage and then use the methods on the resulting object to add the content to it.