You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To see a full code sample that includes an HTML implementation, see [Create presentation](https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/document/create-presentation.yaml).
154
154
155
+
## Detect the presentation's active view and handle the ActiveViewChanged event
156
+
157
+
If you're building a [content add-in](../design/content-add-ins.md), you'll need to get the presentation's active view and handle the [Document.ActiveViewChanged](/javascript/api/office/office.eventtype#fields) event as part of your [Office.onReady](/javascript/api/office#office-office-onready-function(1)) call.
158
+
159
+
> [!NOTE]
160
+
> In PowerPoint on the web, the `Document.ActiveViewChanged` event will never fire because **Slide Show** mode is treated as a new session. In this case, the add-in must fetch the active view on load, as shown in the following code sample.
161
+
162
+
Note the following about the code sample:
163
+
164
+
- The `getActiveFileView` function calls the [Document.getActiveViewAsync](/javascript/api/office/office.document#office-office-document-getactiveviewasync-member(1)) method to return whether the presentation's current view is "edit" (any of the view where you can edit slides, such as **Normal**, **Slide Sorter**, or **Outline**) or "read" (**Slide Show** or **Reading View**), represented by the [ActiveView](/javascript/api/office/office.activeview) enum.
165
+
- The `registerActiveViewChanged` function calls the [Document.addHandlerAsync](/javascript/api/office/office.document#office-office-document-addhandlerasync-member(1)) method to register a handler for the `Document.ActiveViewChanged` event.
166
+
- To display information, this example uses the `showNotification` function, which is included in the Visual Studio Office Add-ins project templates. If you aren't using Visual Studio to develop your add-in, you'll need to replace the `showNotification` function with your own code.
167
+
168
+
```js
169
+
// General Office.onReady function. Called after the add-in loads and Office JS is initialized.
170
+
Office.onReady(() => {
171
+
// Get whether the current view is edit or read.
172
+
constcurrentView=getActiveFileView();
173
+
174
+
// Register the active view changed handler.
175
+
registerActiveViewChanged();
176
+
177
+
// Render the content based off of the current view.
178
+
if (currentView ===Office.ActiveView.Read) {
179
+
// Handle read view.
180
+
console.log('Current view is read.');
181
+
// You can add any specific logic for the read view here.
182
+
} else {
183
+
// Handle edit view.
184
+
console.log('Current view is edit.');
185
+
// You can add any specific logic for the edit view here.
0 commit comments