Problem With Self-invoking Functions Calling Other Functions
In my index.html file (before closing body tag), I want a function to self-invoke itself when the page is loaded. However, I am having issues when the function (here, setUp) is def
Solution 1:
- You want to run Google Apps Script when HTML is loaded.
If my understanding is correct, how about this modification? The flow of this modified script is as follows.
- When the HTML is opened,
google.script.run
is run andsetUp()
of Google Apps Script is run. - When
setUp()
is finished,"ok"
fromsetUp()
is returned and the returned value is shown usingconsole.log()
atwithSuccessHandler()
.- In this modified script, you can see
Done: ok
at the console of browser.
- In this modified script, you can see
Modified script:
Please modify HTML and Google Apps Script on your script editor as follows.
HTML & Javascript:Index.html
<script>window.onload = google.script.run.withSuccessHandler((e) => {console.log("Done: " + e)}).setUp();
</script>
Google Apps Script: Code.gs
function setUp() {
// dateHelper_();return"ok"; // In this modification, as a sample, "ok" is returned.
}
Note:
- Although I'm not sure about your whole situation, HTML can be opened by a dialog, sidebar and Web Apps.
Reference:
If I misunderstood your question and this was not the result you want, I apologize.
Post a Comment for "Problem With Self-invoking Functions Calling Other Functions"