クラス google.script.history(クライアントサイド API)
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
詳細なドキュメント
push(stateObject, params, hash)
提供された状態オブジェクト、URL パラメータ、URL フラグメントをブラウザ履歴にプッシュする
説明します。状態オブジェクトは、デベロッパーが定義するシンプルな JavaScript オブジェクトで、
アプリの現在の状態に関連するデータを含む。この方法は
pushState()
呼び出します。
Index.html
var now = new Date();
var state = {
'timestamp': now.getTime()
};
var params = {
'options': "none"
};
google.script.history.push(state, params, "anchor1");
パラメータ
名前 | 型 | 説明 |
stateObject | Object | 作成される開発者定義のオブジェクトは
関連付けられ、状態がポップされたときに再表示されます。通常
後で取得できるように、アプリケーションの状態情報(ページデータなど)を保存するために使用されます。 |
params | Object | リンク先 URL パラメータを含むオブジェクト
関連付けられていますたとえば、{foo: “bar”, fiz: “baz”} は以下に相当します。
"?foo=bar&fiz=baz" 。または、配列を使用することもできます。
{foo: [“bar”, “cat”], fiz: “baz”} は "?foo=bar&foo=cat&fiz=baz" に相当します。
null または未定義の場合、現在の URL パラメータは変更されません。空の場合、URL パラメータは次のようになります。
消去しました。
|
hash | String | 後に表示される文字列の URL の一部は、
「#」あります。null または未定義の場合、現在の URL の一部は変更されません。空の場合、
URL フラグメントがクリアされました。
|
replace(stateObject, params, hash)
ブラウザ履歴スタックの一番上のイベントを、指定された(デベロッパー定義の)状態に置き換えます
URL パラメータ、URL フラグメントですこれ以外は
push()。
Index.html
var now = new Date();
var state = {
'timestamp': now.getTime()
};
var params = {
'options': "none"
};
google.script.history.replace(state, params, "anchor1");
パラメータ
名前 | 型 | 説明 |
stateObject | Object | 作成される開発者定義のオブジェクトは
関連付けられ、状態がポップされたときに再表示されます。通常
後で取得できるように、アプリケーションの状態情報(ページデータなど)を保存するために使用されます。 |
params | Object | リンク先 URL パラメータを含むオブジェクト
関連付けられていますたとえば、{foo: “bar”, fiz: “baz”} は以下に相当します。
"?foo=bar&fiz=baz" 。または、配列を使用することもできます。
{foo: [“bar”, “cat”], fiz: “baz”} は "?foo=bar&foo=cat&fiz=baz" に相当します。
null または未定義の場合、現在の URL パラメータは変更されません。空の場合、URL パラメータは次のようになります。
消去しました。
|
hash | String | 後に表示される文字列の URL の一部は、
「#」あります。null または未定義の場合、現在の URL の一部は変更されません。空の場合、
URL フラグメントがクリアされました。
|
setChangeHandler(function)
ブラウザ履歴の変更に応答するコールバック関数を設定します。コールバック関数
1 つのイベント オブジェクトのみを引数として取ります。
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...
});
パラメータ
名前 | 型 | 説明 |
function | Function | クライアントサイド
コールバック関数を使用して、履歴変更イベント時に
イベント オブジェクトを唯一の引数として受け取ります。
|
イベント オブジェクト
フィールド |
e.state |
ポップされたイベントに関連付けられている状態オブジェクト。このオブジェクトは状態オブジェクトと
対応する push() または
ポップされた状態を追加した replace() メソッド
履歴スタックに割り当てられます
{"page":2, "name":"Wilbur"}
|
e.location |
location オブジェクト
関連するイベントが表示されます
{"hash":"", "parameter":{"name": "alice", "n": "1"}, "parameters":{"name": ["alice"], "n": ["1", "2"]}}
|
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 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*** ** * ** ***"]]