คลาส google.script.url (API ฝั่งไคลเอ็นต์)
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
google.script.url
เป็น JavaScript ฝั่งไคลเอ็นต์แบบไม่พร้อมกัน
API ที่ค้นหา URL เพื่อรับส่วนย่อยและพารามิเตอร์ของ URL ปัจจุบันได้
API นี้รองรับgoogle.script.history
API ใช้ได้เฉพาะในบริบทของเว็บแอปที่ใช้
IFRAME
ไม่ได้มีไว้สำหรับใช้กับแถบด้านข้างและกล่องโต้ตอบในส่วนเสริม หรือ
และบริบทสคริปต์คอนเทนเนอร์ สำหรับข้อมูลเพิ่มเติม โปรดดู
คู่มือการใช้เบราว์เซอร์
ในเว็บแอป
เมธอด
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
getLocation(function) |
void |
รับออบเจ็กต์ตำแหน่ง URL และส่งไปยัง Callback ที่ระบุ
|
เอกสารโดยละเอียด
getLocation(function)
รับออบเจ็กต์ตำแหน่ง URL และส่งไปยัง Callback ที่ระบุ
(เป็นอาร์กิวเมนต์เดียว)
Index.html
google.script.url.getLocation(function(location) {
console.log(location.parameters);
console.log(location.hash);
});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
function | Function | ฝั่งไคลเอ็นต์
ฟังก์ชัน Callback ที่จะเรียกใช้ โดยใช้
location object เป็นอาร์กิวเมนต์เดียว
|
ออบเจ็กต์ตำแหน่ง
ตารางต่อไปนี้แสดงตัวอย่างองค์ประกอบสถานที่ที่จะระบุหาก
มีการค้นหา URL ต่อไปนี้:
http://www.example.com?n=1&name=alice&n=2#headingAnchor
ช่อง |
location.hash |
ค่าสตริงของส่วนย่อย URL หลังอักขระ #
หรือสตริงว่างหากไม่มีส่วนย่อย URL
headingAnchor
|
location.parameter |
ออบเจ็กต์ของคู่คีย์/ค่าที่สอดคล้องกับคำขอ URL
พารามิเตอร์ ระบบจะแสดงผลเฉพาะค่าแรกสำหรับพารามิเตอร์
ที่มีหลายค่า หากไม่มีพารามิเตอร์
เป็นวัตถุว่างเปล่า
{"name": "alice", "n": "1"}
|
location.parameters |
วัตถุที่คล้ายกับ location.parameter แต่มี
อาร์เรย์ของค่าสำหรับแต่ละคีย์ หากไม่มีพารามิเตอร์
เป็นวัตถุว่าง
{"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.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*** ** * ** ***"]]