Classe google.script.history (API côté client)
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
google.script.history
est une API JavaScript côté client asynchrone qui peut interagir
avec la pile d'historique du navigateur. Il ne peut être utilisé que dans le contexte
d'une application Web qui utilise
IFRAME
Elle n'est pas destinée à être utilisée avec les barres latérales et les boîtes de dialogue d'un module complémentaire ou
conteneur-script. Pour en savoir plus, consultez les
guide d'utilisation du navigateur
dans les applications Web.
Méthodes
Méthode | Type renvoyé | Brève description |
push(stateObject, params, hash) |
void |
Transfère l'objet d'état, les paramètres d'URL et le fragment d'URL fournis à l'historique du navigateur.
pile. |
replace(stateObject, params, hash) |
void |
Remplace l'événement principal de la pile de l'historique du navigateur par l'objet d'état fourni (URL).
et le fragment d'URL. |
setChangeHandler(function) |
void |
Définit une fonction de rappel pour répondre aux modifications apportées à l'historique du navigateur |
Documentation détaillée
push(stateObject, params, hash)
Transfère l'objet d'état, les paramètres d'URL et le fragment d'URL fournis à l'historique du navigateur.
pile. L'objet état est un objet JavaScript simple défini par le développeur et pouvant
ne contiennent aucune donnée pertinente pour l'état actuel de l'application. Cette méthode est analogue à la méthode
pushState()
JavaScript.
Index.html
var now = new Date();
var state = {
'timestamp': now.getTime()
};
var params = {
'options': "none"
};
google.script.history.push(state, params, "anchor1");
Paramètres
Nom | Type | Description |
stateObject | Object | Un objet défini par le développeur à
associé à un événement d'historique de navigateur et qui réapparaît lorsque l'état est renvoyé. Habituellement
utilisées pour stocker des informations sur l'état de l'application (telles que les données de page) en vue de leur récupération ultérieure. |
params | Object | Un objet contenant des paramètres d'URL pour
associer à cet état. Par exemple, {foo: “bar”, fiz: “baz”} équivaut à
"?foo=bar&fiz=baz" Vous pouvez également utiliser des tableaux:
{foo: [“bar”, “cat”], fiz: “baz”} équivaut à "?foo=bar&foo=cat&fiz=baz" .
Si la valeur est nulle ou non définie, les paramètres d'URL actuels ne sont pas modifiés. Si ce champ n'est pas renseigné, les paramètres d'URL sont
effacés.
|
hash | String | Le fragment d'URL de chaîne apparaissant après
le "#" . S'il est nul ou non défini, le fragment d'URL actuel n'est pas modifié. Si ce champ est vide,
Le fragment d'URL est effacé.
|
replace(stateObject, params, hash)
Remplace l'événement principal de la pile de l'historique du navigateur par l'état fourni (défini par le développeur).
les paramètres d'URL et le fragment d'URL. Par ailleurs, il est identique à
push().
Index.html
var now = new Date();
var state = {
'timestamp': now.getTime()
};
var params = {
'options': "none"
};
google.script.history.replace(state, params, "anchor1");
Paramètres
Nom | Type | Description |
stateObject | Object | Un objet défini par le développeur à
associé à un événement d'historique de navigateur et qui réapparaît lorsque l'état est renvoyé. Habituellement
utilisées pour stocker des informations sur l'état de l'application (telles que les données de page) en vue de leur récupération ultérieure. |
params | Object | Un objet contenant des paramètres d'URL pour
associer à cet état. Par exemple, {foo: “bar”, fiz: “baz”} équivaut à
"?foo=bar&fiz=baz" Vous pouvez également utiliser des tableaux:
{foo: [“bar”, “cat”], fiz: “baz”} équivaut à "?foo=bar&foo=cat&fiz=baz" .
Si la valeur est nulle ou non définie, les paramètres d'URL actuels ne sont pas modifiés. Si ce champ n'est pas renseigné, les paramètres d'URL sont
effacés.
|
hash | String | Le fragment d'URL de chaîne apparaissant après
le "#" . S'il est nul ou non défini, le fragment d'URL actuel n'est pas modifié. Si ce champ est vide,
Le fragment d'URL est effacé.
|
setChangeHandler(function)
Définit une fonction de rappel pour répondre aux modifications apportées à l'historique du navigateur. La fonction de rappel
ne doit utiliser qu'un seul objet événement comme argument.
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...
});
Paramètres
Nom | Type | Description |
function | Function | côté client
de rappel à exécuter lors d'un événement de modification de l'historique, à l'aide de la méthode
event comme seul argument.
|
Objet événement
Champs |
e.state |
Objet état associé à l'événement transmis. Cet objet est identique à l'état
utilisé dans la fonction push() correspondante
replace() qui a ajouté l'état d'affichage.
à la pile "Historique".
{"page":2, "name":"Wilbur"}
|
e.location |
Un objet de localisation
associé à l'événement renvoyé
{"hash":"", "parameter":{"name": "alice", "n": "1"}, "parameters":{"name": ["alice"], "n": ["1", "2"]}}
|
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/26 (UTC).
[null,null,["Dernière mise à jour le 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*** ** * ** ***"]]