Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
google.script.url là một JavaScript phía máy khách không đồng bộ
API có thể truy vấn các URL để lấy phân đoạn và tham số URL hiện tại.
API này hỗ trợ google.script.history
API. Chỉ có thể dùng trong ngữ cảnh của một ứng dụng web sử dụng
IFRAME.
Tính năng này không nhằm sử dụng với thanh bên và hộp thoại trong tiện ích bổ sung hoặc
ngữ cảnh tập lệnh vùng chứa. Để biết thêm thông tin, hãy xem
hướng dẫn sử dụng trình duyệt
nhật ký hoạt động trong ứng dụng web.
phía máy khách
để chạy, sử dụng hàm callback
đối tượng vị trí làm đối số duy nhất.
Đối tượng vị trí
Bảng sau đây hiển thị ví dụ về các phần tử vị trí sẽ được chỉ định nếu
URL sau đã được truy vấn: http://www.example.com?n=1&name=alice&n=2#headingAnchor
Trường
location.hash
Giá trị chuỗi của phân đoạn URL sau ký tự #,
hoặc một chuỗi trống nếu không có phân đoạn URL
headingAnchor
location.parameter
Đối tượng của các cặp khoá/giá trị tương ứng với yêu cầu URL
tham số. Hệ thống sẽ chỉ trả về giá trị đầu tiên cho thông số
có nhiều giá trị. Nếu không có tham số nào, hàm này sẽ
là đối tượng trống.
{"name": "alice", "n": "1"}
location.parameters
Một đối tượng tương tự như location.parameter, nhưng có
một mảng giá trị cho mỗi khoá. Nếu không có tham số nào, hàm này sẽ
là đối tượng trống.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003e\u003ccode\u003egoogle.script.url\u003c/code\u003e is a client-side JavaScript API for querying URLs to get parameters and fragments within web apps.\u003c/p\u003e\n"],["\u003cp\u003eThis API works with \u003ccode\u003egoogle.script.history\u003c/code\u003e and requires the use of \u003ccode\u003eIFRAME\u003c/code\u003e in your web app.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetLocation()\u003c/code\u003e method retrieves a URL location object containing parameters and hash information, passing it to a callback function.\u003c/p\u003e\n"],["\u003cp\u003eThe location object provides access to URL components like hash, individual parameters, and all parameter values.\u003c/p\u003e\n"]]],[],null,["# Class google.script.url (Client-side API)\n\n`google.script.url` is an asynchronous client-side JavaScript\nAPI that can query URLs to obtain the current URL parameters and fragment.\nThis API supports the [`google.script.history`](/apps-script/guides/html/reference/history)\nAPI. 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| [getLocation(function)](#getLocation(Function)) | `void` | Gets a URL location object and passes it to the specified callback function. |\n\nDetailed documentation\n----------------------\n\n### `getLocation(function)`\n\nGets a [URL location object](#locationObject) and passes it to the specified callback\nfunction (as the only argument). \n\n### Index.html\n\n```html\ngoogle.script.url.getLocation(function(location) {\n console.log(location.parameters);\n console.log(location.hash);\n});\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|------------|------------------------------------------------------------------------------------------------------------|\n| `function` | `Function` | a client-side callback function to run, using the [location object](#locationObject) as the only argument. |\n\n#### Location object\n\nThe 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`\n\n| Fields ||\n|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `location.hash` | The string value of URL fragment after the `#` character, or an empty string if no URL fragment is present ``` headingAnchor ``` |\n| `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\"} ``` |\n| `location.parameters` | An object similar to `location.parameter`, but with an array of values for each key. If no parameters are present, this will be an empty object. ``` {\"name\": [\"alice\"], \"n\": [\"1\", \"2\"]} ``` |\n\n*** ** * ** ***"]]