scope_extensions
scope_extensions
清单成员用于将 Web 应用的范围扩展到包含其他源。这允许将多个域呈现为一个 Web 应用。
语法
"scope_extensions": [
{ "type": "origin", "origin": "https://support.example.com"},
{ "type": "origin", "origin": "https://shop.example.com"},
{ "type": "origin", "origin": "https://example.de"},
{ "type": "origin", "origin": "https://example.co.uk"}
]
值
scope_extensions
-
一个包含以下属性的对象的数组
描述
scope_extensions
清单成员可以扩展 Web 应用的范围以包含其他源。典型用例包括:
- 用于内容或功能的不同子域,例如
https://support.example.com
、https://shop.example.com
、https://maps.example.com
、https://auth.example.com
。 - 用于语言/地区的不同子域,例如
https://uk.example.com
、https://de.example.com
、https://jp.example.com
、https://no.example.com
。 - 相关的独立域,例如
https://example.jp
、https://my-example.com
、https://my-partner-site.com
、https://example.slack.com
。
主 Web 应用(例如 https://example.com
)需要在其 scope_extensions
清单成员中包含其希望包含在其范围内的源。
{
"scope_extensions": [
{ "type": "origin", "origin": "https://example.jp" },
{ "type": "origin", "origin": "https://my-example.com" },
{ "type": "origin", "origin": "https://my-partner-site.com" },
{ "type": "origin", "origin": "https://example.slack.com" }
]
}
通过 .well-known 文件选择加入
要选择加入关联,在 Web 应用的 scope_extensions
清单成员中指定为范围内的站点的源需要在相对 URL /.well-known/web-app-origin-association
处包含一个名为 web-app-origin-association
的 .well-known 文件。这必须包含一个 JSON 结构,其中包含一个或多个属性,这些属性的键等于该站点选择加入范围的每个 Web 应用的 id
清单成员。
例如
{
"https://example.com": {
"scope": "/"
},
"https://beta.example.com": {
"scope": "/"
}
}
每个属性的值是一个对象,其中包含一个 scope
属性,其值指定将包含在引用 Web 应用范围内的确切路径。
注意:无法为同一个 Web 应用指定不同的范围 — 您不能为同一个键包含多个条目。
scope_extensions
的效果
一旦 Web 应用的 scope_extensions
中包含的源成功选择加入,您就可以链接到这些源范围内的位置,并且当点击链接时,这些位置将显示在应用窗口中,与位于 Web 应用自身范围内的位置一样。
如果您点击链接到不在 Web 应用范围内的位置,它将按预期显示为外部位置。
示例
以位于 https://example.com/app
的示例 Web 应用为例
{
"id": "https://example.com/app",
"name": "My App",
"icons": [
{
"src": "icon/hd_hi",
"sizes": "128x128"
}
],
"start_url": "/app/index.html",
"scope": "/app",
"display": "standalone",
"scope_extensions": [
{ "type": "origin", "origin": "https://example.co.uk" },
{ "type": "origin", "origin": "https://help.example.com" }
]
}
为了选择加入该应用的范围,https://example.co.uk
和 https://help.example.com
需要包含一个如下所示的 /.well-known/web-app-origin-association
文件。
{
"https://example.com/app": {
"scope": "/"
}
}
规范
规范 |
---|
清单孵化 # scope_extensions 成员 |
浏览器兼容性
加载中…
另见
scope
manifest 成员