Scott
Scott

Reputation: 485

How can I get the URL in Google AppMaker?

I am trying to get the current URL in an AppMaker app. However, the standard JavaScript ways do not work, ScriptApp is not available in AppMaker, and the objects that are in AppMaker do not return the correct URL (that starts with https://script.google.com).

Thanks for any suggestions.

Upvotes: 1

Views: 1469

Answers (2)

Oleksii Zemliakov
Oleksii Zemliakov

Reputation: 135

To have an app URL on client side, you can load it during app startup. Firstly, let's create server script that returns app URL:

/**
 *  Get the URL of the published web app.
 */
function getAppUrl() {
  return ScriptApp.getService().getUrl();
}

Open your Project settings and put next code to App startup script section:

loader.suspendLoad();

google.script.run.withSuccessHandler(function(url) {
  appUrl = url;
  loader.resumeLoad();
}).getAppUrl();

screenshot

Now you are able to use appUrl everywhere in Client Scripts.

Using this approach you can create initial app config on startup that requires specific data from server.

Upvotes: 3

Juan Diego Antezana
Juan Diego Antezana

Reputation: 912

You can run a backend/serverside script and use Apps Script

ScriptApp.getService().getUrl()

See the doc ScriptApp Documentation

Upvotes: 7

Related Questions