מחלקה של google.script.history (ממשק API בצד הלקוח)
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
google.script.history
הוא ממשק API אסינכרוני של JavaScript בצד הלקוח שיכול לקיים אינטראקציה
במקבץ של היסטוריית הדפדפן. ניתן להשתמש בה רק בהקשר של אפליקציית אינטרנט שמשתמשת
IFRAME
היא לא מיועדת לשימוש עם סרגלי צד ותיבות דו-שיח בתוסף, או
הקשר לסקריפט קונטיינר. מידע נוסף זמין במאמר
מדריך לשימוש בדפדפן
ההיסטוריה באפליקציות אינטרנט.
מסמכי תיעוד מפורטים
push(stateObject, params, hash)
דוחף את אובייקט המצב, הפרמטרים של כתובת האתר והמקטע של כתובת האתר שצוינו להיסטוריית הדפדפן
סטאק. אובייקט המצב הוא אובייקט JavaScript פשוט המוגדר על ידי המפתח ויכול
מכילים את כל הנתונים שרלוונטיים למצב הנוכחי של האפליקציה. השיטה הזו מקבילה
pushState()
שיטת JavaScript.
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 | אובייקט שמכיל פרמטרים של כתובת אתר כדי
לשייך למצב הזה. לדוגמה, {foo: “bar”, fiz: “baz”} שווה ל-
"?foo=bar&fiz=baz" . לחלופין, אפשר להשתמש במערכים:
{foo: [“bar”, “cat”], fiz: “baz”} שווה ל-"?foo=bar&foo=cat&fiz=baz" .
אם הערך הוא null או לא מוגדר, הפרמטרים הנוכחיים של כתובת ה-URL לא ישתנו. אם השדה ריק, הפרמטרים של כתובת האתר
בוצע ניקוי.
|
hash | String | המקטע של כתובת ה-URL במחרוזת שמופיע אחרי
'#' . אם הערך הוא null או לא מוגדר, המקטע הנוכחי של כתובת ה-URL לא ישתנה. אם השדה ריק,
המקטע של כתובת ה-URL הוסר.
|
replace(stateObject, params, hash)
החלפת האירוע העליון במקבץ של היסטוריית הדפדפן במצב שסופק (מוגדר על ידי המפתח)
אובייקט, פרמטרים של כתובת אתר ומקטע של כתובת 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 | אובייקט שמכיל פרמטרים של כתובת אתר כדי
לשייך למצב הזה. לדוגמה, {foo: “bar”, fiz: “baz”} שווה ל-
"?foo=bar&fiz=baz" . לחלופין, אפשר להשתמש במערכים:
{foo: [“bar”, “cat”], fiz: “baz”} שווה ל-"?foo=bar&foo=cat&fiz=baz" .
אם הערך הוא null או לא מוגדר, הפרמטרים הנוכחיים של כתובת ה-URL לא ישתנו. אם השדה ריק, הפרמטרים של כתובת האתר
בוצע ניקוי.
|
hash | String | המקטע של כתובת ה-URL במחרוזת שמופיע אחרי
'#' . אם הערך הוא null או לא מוגדר, המקטע הנוכחי של כתובת ה-URL לא ישתנה. אם השדה ריק,
המקטע של כתובת ה-URL הוסר.
|
setChangeHandler(function)
מגדירה פונקציית קריאה חוזרת שמגיבה לשינויים בהיסטוריית הדפדפן. פונקציית קריאה חוזרת
צריך לקחת רק אובייקט אירוע אחד כארגומנט.
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 | בצד הלקוח
להפעיל את פונקציית הקריאה החוזרת כשמתרחש אירוע שינוי בהיסטוריה, באמצעות
אובייקט event כארגומנט היחיד.
|
אובייקט אירוע
שדות |
e.state |
אובייקט המצב שמשויך לאירוע הקופץ. האובייקט הזה זהה למצב
שבו נעשה שימוש בפונקציה push() או
השיטה replace() שהוסיפה את מצב החלון הקופץ
למקבץ ההיסטוריה.
{"page":2, "name":"Wilbur"}
|
e.location |
אובייקט מיקום
שמשויכים לאירוע שקופץ
{"hash":"", "parameter":{"name": "alice", "n": "1"}, "parameters":{"name": ["alice"], "n": ["1", "2"]}}
|
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 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*** ** * ** ***"]]