问题
edit: wound up using cheerio to manipulate the elements instead of creating them in a sidebar.
Is it possible to create an execute htmlOutput
in a background page, or do so without showing the user anything?
Sample code below:
plugin.gs
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('Start', 'run')
.addToUi();
}
/**
* Opens a sidebar in the document containing the add-on's user interface.
*/
function run() {
var ui = HtmlService.createTemplateFromFile('sidebar').evaluate()
.setTitle(constants.title);
DocumentApp.getUi().showSidebar(ui);
}
sidebar.html
<html>
<head>
<script>
console.log("Hello world!");
</script>
</head>
</html>
This works, but it pops open the sidebar. If I comment out DocumentApp.getUi().showSidebar(ui);
, then the page is never created or executed.
Context: I'd like to run some scripts that need to use basic APIs/DOM manipulation like window
, document
, etc. These don't run on serverside gs
files. I want this to happen without having to open a sidebar.
来源:https://stackoverflow.com/questions/61579707/execute-htmloutput-code-in-google-app-script-without-opening-a-sidebar