在谷歌应用程序脚本(谷歌文档)中注入外部 javascript 文件 [英] inject external javascript file in google app script(Google Docs)
问题描述
请告诉我如何在谷歌应用脚本(谷歌文档)中注入外部 javascript 文件.
Please let me know how to inject external javascript file in google app script(Google Docs).
提前致谢.
推荐答案
根据您所说的 Inject,一个可能的答案是使用标准的 javascript eval() 函数和 UrlFetchApp:
Depending on what you mean by Inject, one possible answer is to use the standard javascript eval() function along with UrlFetchApp:
eval(UrlFetchApp.fetch('http://path.to/external/javascript.js').getContentText());
如果您想在已发布脚本的 HTML 输出中包含 JS 文件,只需在您的 HTML 中使用标签包含 javascript.
If you want to include a JS file in the HTML output of a published script, simply include the javascript using tags in your HTML.
<script src="http://path.to/external/javascript.js"></script>
评估文档:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/evalUrlfetchApp 文档:https://developers.google.com/应用程序脚本/参考/url-fetch/url-fetch-app
Eval docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval UrlfetchApp docs: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
这篇关于在谷歌应用程序脚本(谷歌文档)中注入外部 javascript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!