Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get current page url

On a web app using GAS HtmlService I need to get the url of current page to build a new link within a template.

The web app will run in a Google sites page (GAS as gadget) but also standalone

I am trying "var pageUrl = document.location.href" and then use pageUrl within a Html template like follow. I know it's wrong, but I am lost, Sorry.

<a href="<?= pageUrl + "?item=xyz" ?>" >Item xyz link</a>

Thanks, Fausto

like image 983
Fausto R. Avatar asked Jan 03 '13 03:01

Fausto R.


1 Answers

You can get the url for a webapp via ScriptApp:

<a href="<?= ScriptApp.getService().getUrl() + "?item=xyz" ?>" >Item xyz link</a>

and you can get the url in sites via SitesApp:

SitesApp.getActivePage().getUrl()

although I don't think that's actually useful for what you seem to be describing since you can't add useful query parameters to it. Scripts run in iframes, so although you can use document.location on the client, it won't help you anyways. The URL is sanitized and the service id is stripped out.

like image 195
Corey G Avatar answered Oct 21 '22 19:10

Corey G