只读 Presentation 属性 receiver , which is only available in browser contexts which are receiving a presentation, returns the PresentationReceiver object which can be used to access and communicate with the browser context which controls the presentation. This property is always null when accessed from outside a browser context which is receiving a presentation.

句法

receiver = Presentation.receiver;
receiver = navigator.presentation.receiver;
					

由于 Presentation interface is typically accessed through navigation.presentation , the second form of the syntax shown above is the more commonly used.

If the code is running in a context which is receiving a presentation, the returned value is a PresentationReceiver which can then be used to communicate with the context which is the source of the presentation.

If the current context is not receiving a presentation, receiver is null .

范例

Determining whether or not the context is receiving a presentation

You can easily determine whether or not the context is the receiver for a presentation by checking the value of navigator.receiver . If it's a non-null value, then the context is indeed receiving a presentation. If it's null , there's no incoming presentation.

if (navigator.receiver) {
  footer.innerHTML = "Receiving presentation";
}  else {
  footer.innerHTML = "(idle)";
}
					

Accessing the connection list

此范例使用 receiver to access the list of incoming connections and to build and display a list of those connections' ID strings.

let listElem = document.getElementById("connectionview");
navigator.presentation.receiver.connectionList
          .then(function(connections) {
    connections.forEach(function(aConnection)) {
      listElem.innerHTML += "<li>" + aConnection.id
            + "</li>";
    });
});
					

After getting access to the output list element in the variable connectionView , navigator.receiver is used to get a reference to the PresentationReceiver object for this context, and its connectionList is used to get a Promise which will be called when the list is available.

The promise handler receives as its input parameter an array of the incoming connections. We iterate over these using forEach() , appending a new item to the connectionView list element for each connection.

规范

规范 状态 注释
Presentation API
The definition of 'receiver' in that specification.
候选推荐

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
receiver Chrome 48 Edge ≤79 Firefox 51 IE No Opera Yes Safari ? WebView Android No Chrome Android 48 Firefox Android 51 Opera Android Yes Safari iOS ? Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改:
  1. Presentation
  2. 特性
    1. defaultRequest
    2. receiver