origin
只读特性在
ExtendableMessageEvent
interface returns the origin of the
Client
that sent the message.
var myOrigin = extendableMessageEvent.origin;
A
USVString
.
When the following code is used inside a service worker to respond to a push messages by sending the data received via
PushMessageData
to the main context via a
channel message
, the event object of
onmessage
将是
ExtendableMessageEvent
.
var port;
self.addEventListener('push', function(e) {
var obj = e.data.json();
if(obj.action === 'subscribe' || obj.action === 'unsubscribe') {
port.postMessage(obj);
} else if(obj.action === 'init' || obj.action === 'chatMsg') {
port.postMessage(obj);
}
});
self.onmessage = function(e) {
console.log(e.origin);
port = e.ports[0];
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
服务工作者
The definition of 'ExtendableMessageEvent.origin' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
origin
|
Chrome ? | Edge ? | Firefox 不支持 No | IE 不支持 No | Opera ? | Safari 不支持 No | WebView Android 不支持 No | Chrome Android ? | Firefox Android 不支持 No | Opera Android ? | Safari iOS 不支持 No | Samsung Internet Android ? |
不支持
兼容性未知
实验。期望将来行为有所改变。
ExtendableMessageEvent
data
lastEventId
origin
ports
source
缓存
CacheStorage
Client
Clients
ExtendableEvent
FetchEvent
InstallEvent
Navigator.serviceWorker
NotificationEvent
PeriodicSyncEvent
PeriodicSyncManager
PeriodicSyncRegistration
ServiceWorker
ServiceWorkerContainer
ServiceWorkerGlobalScope
ServiceWorkerRegistration
SyncEvent
SyncManager
SyncRegistration
WindowClient