Class google.script.url (Client-side API) Stay organized with collections Save and categorize content based on your preferences.
Page Summary
google.script.urlis a client-side JavaScript API for querying URLs to get current URL parameters and fragments.This API works with the
google.script.historyAPI and is intended for web apps usingIFRAME.It is not for use in sidebars or dialogs within add-ons or container-script contexts.
The
getLocation(function)method gets a URL location object and passes it to a specified callback function.The location object contains fields like
location.hash,location.parameter, andlocation.parametersto access parts of the URL.
google.script.url is an asynchronous client-side JavaScript API that can query URLs to obtain the current URL parameters and fragment. This API supports thegoogle.script.history API. It can only be used in the context of a web app that usesIFRAME. It is not intended for use with sidebars and dialogs in an add-on or container-script context. For more information, see theguide to using browser history in web apps.
Methods
| Method | Return type | Brief description |
|---|---|---|
getLocation(function) | void | Gets a URL location object and passes it to the specified callback function. |
Detailed documentation
getLocation(function)
Gets aURL location object and passes it to the specified callback function (as the only argument).
Index.html
google.script.url.getLocation(function(location) { console.log(location.parameters); console.log(location.hash);});Parameters
| Name | Type | Description |
|---|---|---|
function | Function | a client-side callback function to run, using thelocation object as the only argument. |
Location object
The following table shows examples of the location elements that would be specified if the following URL was queried:http://www.example.com?n=1&name=alice&n=2#headingAnchor| Fields | |
|---|---|
location.hash | The string value of URL fragment after the headingAnchor |
location.parameter | An object of key/value pairs that correspond to the URL request parameters. Only the first value will be returned for parameters that have multiple values. If no parameters are present, this will be an empty object. {"name": "alice", "n": "1"} |
location.parameters | An object similar to {"name": ["alice"], "n": ["1", "2"]} |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.