Classe google.script.history (API lato client)
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
google.script.history
è un'API JavaScript lato client asincrona che può interagire
con lo stack della cronologia del browser. Può essere utilizzato solo nel contesto di un'app web che usa
IFRAME
Non è destinata all'utilizzo con barre laterali e finestre di dialogo in un componente aggiuntivo o
contesto container-script. Per ulteriori informazioni, consulta
guida all'uso del browser
la cronologia delle app nelle app web.
Metodi
Metodo | Tipo restituito | Breve descrizione |
push(stateObject, params, hash) |
void |
Esegue il push dell'oggetto di stato, dei parametri URL e del frammento di URL forniti nella cronologia del browser
stack. |
replace(stateObject, params, hash) |
void |
Sostituisce l'evento principale nello stack della cronologia del browser con l'oggetto di stato fornito, l'URL
parametri e frammento di URL. |
setChangeHandler(function) |
void |
Imposta una funzione di callback per rispondere ai cambiamenti nella cronologia del browser |
Documentazione dettagliata
push(stateObject, params, hash)
Esegue il push dell'oggetto di stato, dei parametri URL e del frammento di URL forniti nella cronologia del browser
stack. L'oggetto state è un semplice oggetto JavaScript definito dallo sviluppatore e che può
contenere dati pertinenti allo stato attuale dell'app. Questo metodo è analogo al
pushState()
metodo JavaScript.
Index.html
var now = new Date();
var state = {
'timestamp': now.getTime()
};
var params = {
'options': "none"
};
google.script.history.push(state, params, "anchor1");
Parametri
Nome | Tipo | Descrizione |
stateObject | Object | È un oggetto definito dallo sviluppatore
associate a un evento della cronologia del browser, che si ripresenta quando lo stato viene visualizzato. Tipicamente
utilizzati per archiviare informazioni sullo stato dell'applicazione (ad esempio i dati della pagina) per il recupero futuro. |
params | Object | Un oggetto contenente i parametri URL per
associate a questo stato. Ad esempio, {foo: “bar”, fiz: “baz”} equivale a
"?foo=bar&fiz=baz" . In alternativa, è possibile utilizzare gli array:
{foo: [“bar”, “cat”], fiz: “baz”} equivale a "?foo=bar&foo=cat&fiz=baz" .
Se nullo o non definito, i parametri URL correnti non vengono modificati. Se vuoto, i parametri URL vengono
cancellato.
|
hash | String | Il frammento di URL della stringa visualizzato dopo
il '#' . Se nullo o non definito, il frammento dell'URL corrente non viene modificato. Se vuoto,
Il frammento dell'URL è stato cancellato.
|
replace(stateObject, params, hash)
Sostituisce l'evento principale nello stack della cronologia del browser con lo stato fornito (definito dallo sviluppatore)
parametri URL e frammento URL. Per il resto è identico a
push().
Index.html
var now = new Date();
var state = {
'timestamp': now.getTime()
};
var params = {
'options': "none"
};
google.script.history.replace(state, params, "anchor1");
Parametri
Nome | Tipo | Descrizione |
stateObject | Object | È un oggetto definito dallo sviluppatore
associate a un evento della cronologia del browser, che si ripresenta quando lo stato viene visualizzato. Tipicamente
utilizzati per archiviare informazioni sullo stato dell'applicazione (ad esempio i dati della pagina) per il recupero futuro. |
params | Object | Un oggetto contenente i parametri URL per
associate a questo stato. Ad esempio, {foo: “bar”, fiz: “baz”} equivale a
"?foo=bar&fiz=baz" . In alternativa, è possibile utilizzare gli array:
{foo: [“bar”, “cat”], fiz: “baz”} equivale a "?foo=bar&foo=cat&fiz=baz" .
Se nullo o non definito, i parametri URL correnti non vengono modificati. Se vuoto, i parametri URL vengono
cancellato.
|
hash | String | Il frammento di URL della stringa visualizzato dopo
il '#' . Se nullo o non definito, il frammento dell'URL corrente non viene modificato. Se vuoto,
Il frammento dell'URL è stato cancellato.
|
setChangeHandler(function)
Imposta una funzione di callback per rispondere ai cambiamenti nella cronologia del browser. La funzione di callback
dovrebbe prendere un solo oggetto evento come argomento.
Index.html
google.script.history.setChangeHandler(function (e) {
console.log(e.state);
console.log(e.location.parameters);
console.log(e.location.hash);
// Adjust web app UI to match popped state here...
});
Parametri
Nome | Tipo | Descrizione |
function | Function | un server lato client
di callback da eseguire a seguito di un evento di modifica della cronologia, utilizzando
event oggetto come unico argomento.
|
Oggetto evento
Campi |
e.state |
L'oggetto di stato associato all'evento popped. Questo oggetto è identico allo stato
utilizzato nella funzione push() corrispondente
Metodo replace() che ha aggiunto lo stato popup
alla sequenza della cronologia.
{"page":2, "name":"Wilbur"}
|
e.location |
Un oggetto location
associate all'evento popped
{"hash":"", "parameter":{"name": "alice", "n": "1"}, "parameters":{"name": ["alice"], "n": ["1", "2"]}}
|
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003egoogle.script.history\u003c/code\u003e enables interaction with the browser history stack within web apps using \u003ccode\u003eIFRAME\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods to push, replace, and monitor browser history state, including URL parameters and fragments.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can define custom state objects to store and retrieve application-specific data associated with history events.\u003c/p\u003e\n"],["\u003cp\u003eA change handler can be set to trigger a callback function in response to history changes, allowing dynamic UI updates.\u003c/p\u003e\n"]]],[],null,["# Class google.script.history (Client-side API)\n\n`google.script.history` is an asynchronous client-side JavaScript API that can interact\nwith the browser history stack. It can only be used in the context of a web app that uses\n[`IFRAME`](/apps-script/reference/html/sandbox-mode#properties).\nIt is not intended for use with sidebars and dialogs in an add-on or\ncontainer-script context. For more information, see the\n[guide to using browser\nhistory in web apps](/apps-script/guides/web#web_apps_and_browser_history). \n\n### Methods\n\n| Method | Return type | Brief description |\n|----------------------------------------------------------------------|-------------|----------------------------------------------------------------------------------------------------------------------|\n| [push(stateObject, params, hash)](#push(Object,Object,String)) | `void` | Pushes the provided state object, URL parameters and URL fragment onto the browser history stack. |\n| [replace(stateObject, params, hash)](#replace(Object,Object,String)) | `void` | Replaces the top event on the browser history stack with the provided state object, URL parameters and URL fragment. |\n| [setChangeHandler(function)](#setChangeHandler(Function)) | `void` | Sets a callback function to respond to changes in the browser history |\n\nDetailed documentation\n----------------------\n\n### `push(stateObject, params, hash)`\n\nPushes the provided state object, URL parameters and URL fragment onto the browser history\nstack. The state object is a simple JavaScript Object that is defined by the developer and can\ncontain any data relevant to the app's current state. This method is analogous to the\n[pushState()](https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_pushState()_method)\nJavaScript method. \n\n### Index.html\n\n```html\nvar now = new Date();\nvar state = {\n 'timestamp': now.getTime()\n};\nvar params = {\n 'options': \"none\"\n};\ngoogle.script.history.push(state, params, \"anchor1\");\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `stateObject` | `Object` | An developer-defined object to be associated with a browser history event, and which resurfaces when the state is popped. Typically used to store application state information (such as page data) for future retrieval. |\n| `params` | `Object` | An object containing URL parameters to associate with this state. For example, `{foo: \"bar\", fiz: \"baz\"}` equates to `\"?foo=bar&fiz=baz\"`. Alternatively, arrays can be used: `{foo: [\"bar\", \"cat\"], fiz: \"baz\"}` equates to `\"?foo=bar&foo=cat&fiz=baz\"`. If null or undefined, the current URL parameters are not changed. If empty, the URL parameters are cleared. |\n| `hash` | `String` | The string URL fragment appearing after the '#' character. If null or undefined, the current URL fragment is not changed. If empty, the URL fragment is cleared. |\n\n*** ** * ** ***\n\n*** ** * ** ***\n\n### `replace(stateObject, params, hash)`\n\nReplaces the top event on the browser history stack with the provided (developer-defined) state\nobject, URL parameters and URL fragment. This is otherwise identical to\n[push()](#push(Object,Object,String)). \n\n### Index.html\n\n```html\nvar now = new Date();\nvar state = {\n 'timestamp': now.getTime()\n};\nvar params = {\n 'options': \"none\"\n};\ngoogle.script.history.replace(state, params, \"anchor1\");\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `stateObject` | `Object` | An developer-defined object to be associated with a browser history event, and which resurfaces when the state is popped. Typically used to store application state information (such as page data) for future retrieval. |\n| `params` | `Object` | An object containing URL parameters to associate with this state. For example, `{foo: \"bar\", fiz: \"baz\"}` equates to `\"?foo=bar&fiz=baz\"`. Alternatively, arrays can be used: `{foo: [\"bar\", \"cat\"], fiz: \"baz\"}` equates to `\"?foo=bar&foo=cat&fiz=baz\"`. If null or undefined, the current URL parameters are not changed. If empty, the URL parameters are cleared. |\n| `hash` | `String` | The string URL fragment appearing after the '#' character. If null or undefined, the current URL fragment is not changed. If empty, the URL fragment is cleared. |\n\n*** ** * ** ***\n\n### `setChangeHandler(function)`\n\nSets a callback function to respond to changes in the browser history. The callback function\nshould take only a single [event object](#eventObject) as an argument.\n\n### Index.html\n\n```html\ngoogle.script.history.setChangeHandler(function (e) {\n console.log(e.state);\n console.log(e.location.parameters);\n console.log(e.location.hash);\n\n // Adjust web app UI to match popped state here...\n});\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|------------|----------------------------------------------------------------------------------------------------------------------------------|\n| `function` | `Function` | a client-side callback function to run upon a history change event, using the [event object](#eventObject) as the only argument. |\n\n#### Event object\n\n| Fields ||\n|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `e.state` | The state object associated with the popped event. This object is identical to the state object that used in the corresponding [push()](#push(Object,Object,String)) or [replace()](#replace(Object,Object,String)) method that added the popped state to the history stack. ``` {\"page\":2, \"name\":\"Wilbur\"} ``` |\n| `e.location` | A [location object](/apps-script/guides/html/reference/url#locationObject) associated with the popped event ``` {\"hash\":\"\", \"parameter\":{\"name\": \"alice\", \"n\": \"1\"}, \"parameters\":{\"name\": [\"alice\"], \"n\": [\"1\", \"2\"]}} ``` |\n\n*** ** * ** ***"]]