2

我是使用 Google Script 的新手,但它似乎是我期待使用的 Google Doc、Calendar 和 Mail 软件的迷人界面!

我们小组有一个网站,我想用访问 Google Docs 的动态 Javascript 组件来美化它。我希望做的是在 Google Script 中创建函数并在我们网站的 HTML 中调用它们。

因此,我制作了一个具有两个功能的 Google 脚本页面:

function getName(EMT_ID) {
// ...
};

function getStrikes(EMT_ID) {
// ...
};

这些从我们使用的 Google 电子表格中获取数据。我不会包含详细信息,因为当通过 Google Script 测试环境访问它们时,它们本身就可以正常工作。

然后我将其发布为“Web App”,以便我可以从其他平台访问这些功能。

现在,在我们的另一个网页上,我添加了这段代码(删除了确切的标题)

<script src="https://script.google.com/macros/s/AKfy[...]65K0/exec"></script>

<script>
function strikes()
{
var EMT_ID = document.getElementById('USC ID').value
document.getElementByID('output').InnerHTML = getName(EMT_ID) + ' has ' + getStrikes(EMT_ID) + '     strikes.'
}
</script>

<input type="text" id="USC ID">
<input type="button" onclick='strikes()' value='Check Strikes'>
<p>Output here:</p><p id="output"></p>

我希望这将允许我从 Google Script 页面访问 Javascript 函数。是这样吗?如果不是 - 我应该怎么做。

此致

- - 编辑

添加详细信息 - 网页似乎根本没有响应按下按钮。

4

1 回答 1

0

Google Apps Script functions are not directly callable from external javascript in the way that you've tried. When you published your script as a web app, you were provide a URL that the app was accessible at, via HTML. It didn't expose the functions of your script.

You do have some options, though.

  1. You can create HTML within your google script using the HTML Service, and THAT html can utilize your apps-script functions indirectly via templated HTML or directly like this:

    <script>
      google.script.run.doSomething();
    </script>
    
  2. You can use the Content Service to have your Apps Script provide feeds (RSS, JSON, JSONP).

  3. Your published service can be written using the UI Service, with full access to your other apps script functions, forms, charts, etc.

There are variations on the above themes as well - this list isn't exhaustive.

于 2013-05-13T01:56:36.300 回答