Class Service
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
方法
方法 | 傳回類型 | 簡短說明 |
getUrl() | String | 如果已部署網頁應用程式,則傳回該應用程式的網址;否則傳回 null 。 |
isEnabled() | Boolean | 如果指令碼可做為網頁應用程式存取,則傳回 true 。 |
內容詳盡的說明文件
getUrl()
如果已部署網頁應用程式,就會傳回該應用程式的網址;否則會傳回 null
。如果您執行的是開發模式網頁應用程式,這個方法會傳回開發模式網址。
// Mail the URL of the published web app.
MailApp.sendMail(
'myself@example.com',
'My Snazzy App',
`My new app is now available at ${ScriptApp.getService().getUrl()}`,
);
回攻員
String
:網頁應用程式的網址
isEnabled()
如果指令碼可做為網頁應用程式存取,則傳回 true
。
回攻員
Boolean
:如果指令碼是以網頁應用程式形式發布,則為 true
;如果不是,則為 false
已淘汰的方法
disable()
已淘汰。這個函式已淘汰,不建議在新指令碼中使用。
停用可透過網頁應用程式存取的腳本。這個方法等同於開啟「Publish > Deploy as web app」對話方塊,然後按一下「disable web app」。
ScriptApp.getService().disable();
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eThe \u003ccode\u003eScriptApp\u003c/code\u003e service allows you to control and interact with the deployment of your script as a web application.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve the web app's URL using \u003ccode\u003egetUrl()\u003c/code\u003e, check its accessibility status with \u003ccode\u003eisEnabled()\u003c/code\u003e, and previously, disable it using the now deprecated \u003ccode\u003edisable()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003edisable()\u003c/code\u003e method has been deprecated and should no longer be used in new scripts, replaced by the "Publish > Deploy as web app" dialog for disabling.\u003c/p\u003e\n"],["\u003cp\u003eWhen deploying your script as a web app, you can use provided methods to obtain its URL and determine if it's enabled for access.\u003c/p\u003e\n"]]],[],null,["# Class Service\n\nService\n\nAccess and manipulate script publishing. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------|-------------|------------------------------------------------------------------------------------|\n| [getUrl()](#getUrl()) | `String` | Returns the URL of the web app, if it has been deployed; otherwise returns `null`. |\n| [isEnabled()](#isEnabled()) | `Boolean` | Returns `true` if the script is accessible as a web app. |\n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|-------------------------|-------------|-------------------------------------------------------|\n| [disable()](#disable()) | `void` | Disables the script from being accessed as a web app. |\n\nDetailed documentation\n----------------------\n\n### `get``Url()`\n\nReturns the URL of the web app, if it has been deployed; otherwise returns `null`. If you\nare running the development mode web app, this returns the development mode url.\n\n```javascript\n// Mail the URL of the published web app.\nMailApp.sendMail(\n 'myself@example.com',\n 'My Snazzy App',\n `My new app is now available at ${ScriptApp.getService().getUrl()}`,\n);\n```\n\n#### Return\n\n\n`String` --- the URL of the web app\n\n*** ** * ** ***\n\n### `is``Enabled()`\n\nReturns `true` if the script is accessible as a web app.\n\n#### Return\n\n\n`Boolean` --- `true` if the script is published as a web app; `false` if not\n\nDeprecated methods\n------------------\n\n### `disable()`\n\n\n**Deprecated.** This function is deprecated and should not be used in new scripts.\n\nDisables the script from being accessed as a web app. This method is equivalent to opening the\n\"Publish \\\u003e Deploy as web app\" dialog and clicking \"disable web app\".\n\n```javascript\nScriptApp.getService().disable();\n```"]]