ReferenceError:未定义“document”

时间:2012-11-25 15:06:26

标签: javascript google-apps-script google-sites referenceerror

我是JavaScript的新手,也是Google Apps脚本的新手。我正在尝试一个显示当前日期(仅限日,月e和全年)的简单函数,但Google Script显示错误ReferenceError:“document”未定义。

我的目标是在Google网站中使用此功能。这是代码:

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);
}

2 个答案:

答案 0 :(得分:2)

作为Google Apps脚本运行的代码无法在浏览器中运行,因此您无法使用Web浏览器API。如果您要将内容输出到Google网站,则需要使用API for Sites

据推测,您需要createWebPage之类的内容,然后使用the methods on the resulting object向其中添加内容。

答案 1 :(得分:2)

如前一个答案所述,您无法直接在浏览器中执行某个功能,您必须选择一个所谓的“container”来运行您的功能。我建议您阅读documentation并尝试一些simple tutorials来了解如何执行GAS。


编辑:根据您的评论,随时查看使用UiApp构建的this script,结果可以查看here并显示您想要的内容:“你好,今天是25/10/2012”