# How do I close the window after leaveUrl?

**URL:** <https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065>\
**Category:** Web\
**Created:** [February 10, 2021, 7:02pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065 "2021-02-10T19:02:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dario.mendoza](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dario.mendoza/32/22931_2.png) [@dario.mendoza](https://devforum.zoom.us/u/dario.mendoza)\
**Post date:** [February 10, 2021, 7:02pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/1 "2021-02-10T19:02:10Z")

</div>

at the end of the meeting and click on the exit button after 3 seconds I would like the window to close automatically

 ![code](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/d/f/df7a2ae00eac0856537c76e3f3215103cb3b9bab.png)

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [February 11, 2021, 9:40pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/2 "2021-02-11T21:40:52Z")

</div>

Hey @dario.mendoza,

Thank you for reaching out to the Zoom Developer Forum. There are a couple of options when it comes to this.

1. You can add an event listener for the click event on the Leave button and close the tab when the user confirms they want to leave the meeting.

2. You can add an event listener to the `beforeUnload` or `unload` events so that you can close the child window when the page is redirected

3. You can set your leaveURL to a page you’ve created that automatically closes the child window when it’s opened

I hope that helps! Let me know if you have any questions.

Thanks,  
Max

---

<div class="post-metadata">

**Author:** ![dario.mendoza](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dario.mendoza/32/22931_2.png) [@dario.mendoza](https://devforum.zoom.us/u/dario.mendoza)\
**Post date:** [February 16, 2021, 5:02pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/3 "2021-02-16T17:02:33Z")

</div>

Hi Max, I would like to apply option 1, could you help me with an example of how to close the window once the participant leaves the meeting or leaves the meeting.  
regards  
Dario

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [February 17, 2021, 8:24pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/4 "2021-02-17T20:24:10Z")

</div>

Hey @dario.mendoza ,

You can use the close window javascript function:

[https://developer.mozilla.org/en-US/docs/Web/API/Window/close](https://developer.mozilla.org/en-US/docs/Web/API/Window/close)

You can listen to the `onUserLeave` event via In Meeting Service Listener:

[https://marketplacefront.zoom.us/sdk/meeting/web/ZoomMtg.html#inMeetingServiceListener](https://marketplacefront.zoom.us/sdk/meeting/web/ZoomMtg.html#inMeetingServiceListener)

Let me know if that helps.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![dario.mendoza](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dario.mendoza/32/22931_2.png) [@dario.mendoza](https://devforum.zoom.us/u/dario.mendoza)\
**Post date:** [February 17, 2021, 9:48pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/5 "2021-02-17T21:48:24Z")

</div>

Hi Tommy, I did the exercise with window.close () but in automatic it closes the window (it doesn’t let anything load)

 ![imagen](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/3/c/3cbc034625a69d70c9a5fa388c57f218dec3ec56.png)

---

<div class="post-metadata">

**Author:** ![dario.mendoza](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dario.mendoza/32/22931_2.png) [@dario.mendoza](https://devforum.zoom.us/u/dario.mendoza)\
**Post date:** [February 17, 2021, 9:51pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/6 "2021-02-17T21:51:49Z")

</div>

> [@tommy](#):
>
> `onUserLeave` event

I don’t understand the other exercise (onUserLeave event), could you explain it to me more clearly?  
regards  
Darius  
saludos Tommy

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [February 17, 2021, 11:27pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/7 "2021-02-17T23:27:49Z")

</div>

Hey @dario.mendoza,

Thank you for your questions.

> [@dario.mendoza](#):
>
> I did the exercise with window.close () but in automatic it closes the window (it doesn’t let anything load)

You won’t be able to add a JavaScript function to the leaveUrl property as this expects a string containing the URL to redirect to. Instead, you’ll want to call the `window.close()` function from the `onUserLeave` inMeetingEventListener event. Alternatively, you can use the leaveUrl to redirect to a page that closes the browser window after the page loads.

> [@dario.mendoza](#):
>
> I don’t understand the other exercise (onUserLeave event), could you explain it to me more clearly?

The `onUserLeave` event will fire when a user leaves the meeting. We have an example of how to use this in our [Sample Web App](https://github.com/zoom/sample-app-web) and more information can be found in the [reference documentation](https://marketplace.zoom.us/docs/sdk/native-sdks/web/reference):

> <https://github.com/zoom/meetingsdk-web-sample/blob/0dcfd8c9be2d2a1cc9f6127f781a776bb06b2495/Local/js/meeting.js#L85-L87>

I hope that helps! Let me know if you have any questions.

Thanks,  
Max

---

<div class="post-metadata">

**Author:** ![jake2](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@jake2](https://devforum.zoom.us/u/jake2)\
**Post date:** [February 18, 2021, 4:09am UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/8 "2021-02-18T04:09:21Z")

</div>

Hi MaxM,

in 1.9.0

ZoomMtg.inMeetingServiceListener(“onUserLeave”, () =\> {  
window.close();  
});

does not work, it still redirects and does not close the window

Edit: When the meeting has 2 people in it this does work, but it closes the window for all participants when any one participant leaves. So this is not the correct solution.

---

<div class="post-metadata">

**Author:** ![dario.mendoza](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dario.mendoza/32/22931_2.png) [@dario.mendoza](https://devforum.zoom.us/u/dario.mendoza)\
**Post date:** [February 18, 2021, 4:52pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/9 "2021-02-18T16:52:33Z")

</div>

thanks, jake2 in effect does not work and does not close the window

---

<div class="post-metadata">

**Author:** ![tcsteve](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tcsteve](https://devforum.zoom.us/u/tcsteve)\
**Post date:** [February 18, 2021, 7:17pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/10 "2021-02-18T19:17:38Z")

</div>

I was able to test this with Jake, using 2 computers on different networks in different buildings. I joined as the host, Jake joined after me, Jake left the meeting, and when he did my browser window also closed. So, the onUserLeave event gets fired for every user in the meeting, not just the user who left, and it looks like the event handler gets passed 3 objects, but I don’t see information about the user who left that we could use to determine if the current user left and close only their window. The first parameter to the event handler is an object that contains an exports property, which is an object with a Meeting object, then there’s a numeric id property, and a “loaded” property set to true.

If we can’t catch the current user leaving, then maybe another alternative would be another option like leaveUrl that accepts a function to run when the current user leaves.

---

<div class="post-metadata">

**Author:** ![dario.mendoza](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dario.mendoza/32/22931_2.png) [@dario.mendoza](https://devforum.zoom.us/u/dario.mendoza)\
**Post date:** [February 18, 2021, 9:11pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/11 "2021-02-18T21:11:29Z")

</div>

already solved

in the leaveUrl I directed it to a new example page [leaveUrl: “/endmeeting.html”] and on that page I put what is seen in the image and with that when the user leaves the meeting the window automatically closes.

 ![imagen](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/f/e/fe58413df745f043d73bfe638d89476610303ba9.png)  
thanks: Adrian Ponce

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [February 18, 2021, 10:26pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/12 "2021-02-18T22:26:12Z")

</div>

Hey @jake2, @tcsteve and @dario.mendoza,

Thank you for the update.

> [@jake2](#):
>
> ZoomMtg.inMeetingServiceListener(“onUserLeave”, () =\> {  
> window.close();  
> });

That is correct, you can’t directly call the `window.close()` function unless you want the window to close for all users. You will need to add custom logic to fit your use case.

> [@tcsteve](#):
>
> the onUserLeave event gets fired for every user in the meeting, not just the user who left

If you initialize an inMeetingServiceListener on the page, the user that has that page opened will receive the event but it will only fire for the single user that left the meeting. You can always add an inMeetingServiceListener conditionally.

> [@tcsteve](#):
>
> I don’t see information about the user who left

You should be able to use the `data` argument as shown in the example above to get information about the user leaving the meeting. Here is an example of what I saw when running the code from the [Sample Web App](https://github.com/zoom/sample-app-web):

![image](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/1/9/1913da69f0cd86a22be6a6d6900c070a4cff501c.png)

That userId, in conjunction with the `getCurrentUser()` function should be all you need to close the window for a specific user.

> [@dario.mendoza](#):
>
> I directed it to a new example page [leaveUrl: “/endmeeting.html”] and on that page I put what is seen in the image and with that when the user leaves the meeting the window automatically closes.

Great! I’m glad to hear that method worked for you.

Thanks,  
Max

---

<div class="post-metadata">

**Author:** ![tcsteve](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tcsteve](https://devforum.zoom.us/u/tcsteve)\
**Post date:** [February 18, 2021, 11:12pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/13 "2021-02-18T23:12:51Z")

</div>

Hi Max,

I saw my problem before, we had the event handler set up as an arrow function and I tried to use arguments to see what was being passed to it.

We’re trying to call getCurrentUser, and it’s returning undefined. It looks like the documentation says it expects an empty object as a parameter. We’ve called it with and without a parameter and it’s still showing undefined. Do you know where we’re going wrong?

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [February 19, 2021, 10:12pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/14 "2021-02-19T22:12:46Z")

</div>

Hey @tcsteve ,

> [@tcsteve](#):
>
> We’re trying to call getCurrentUser, and it’s returning undefined. It looks like the documentation says it expects an empty object as a parameter. We’ve called it with and without a parameter and it’s still showing undefined. Do you know where we’re going wrong?

Can you share the code snippet of how you are calling the getCurrentUser function? Make sure you are calling it in the ZoomMtg.join success callback function. 🙂

More details will allow us to better assist.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![tcsteve](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tcsteve](https://devforum.zoom.us/u/tcsteve)\
**Post date:** [February 19, 2021, 10:17pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/15 "2021-02-19T22:17:24Z")

</div>

We’re actually calling it in the onUserLeave event handler, using ZoomMtg.getCurrentUser. The purpose is to figure out if the current user is the user who just left, and close their window if so. We’re registering the event listener right after calling init, not in the success callback for either init or join.

```
			// ZoomMtg.inMeetingServiceListener("onUserLeave", (data) => {
			// console.log("close window");
			// console.log("inMeetingServiceListener onUserLeave", data);
			// const user = ZoomMtg.getCurrentUser({});
			// console.log("ZoomMtg.getCurrentUser({})", user);
			// if(data.userId === user.id) {
			// window.close();
			// }
			// });
```

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [February 19, 2021, 11:26pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/16 "2021-02-19T23:26:06Z")

</div>

Hey @tcsteve,

Thank you for the update. I tested this on my end and saw that the user leaving does not receive the `onUserLeave` event because this event fires after the page is redirected. That’s my mistake for advising you incorrectly.

Instead, you should employ the same method as @dario.mendoza where you redirect to a page that closes the window.

As part of my testing, I found a couple additional tips related to the code snippet:

1. Instead of using `getCurrentUser` to obtain the User ID, you can use the `onUserJoin` event to capture the userId

```auto
  ZoomMtg.inMeetingServiceListener('onUserJoin', (data) => {
    console.log('inMeetingServiceListener onUserJoin', data.userId);
  });

```

1. When using `getCurrentUser` make sure that you are accessing the user information from the `success` callback.

Along those same lines, in order to ensure you get all the information available from that function, it will need to be called from the `success` callback of the `join()` function or via another method that ensures it is called after the user is done joining the meeting.

We have an example of this can be done on the git repo for our [Sample Web App](https://github.com/zoom/sample-app-web):

> <https://github.com/zoom/sample-app-web/blob/0dcfd8c9be2d2a1cc9f6127f781a776bb06b2495/Local/js/meeting.js#L54-L70>

Sorry for the confusion there, I hope this is helpful!

Thanks,  
Max

---

<div class="post-metadata">

**Author:** ![ankur.sharma](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@ankur.sharma](https://devforum.zoom.us/u/ankur.sharma)\
**Post date:** [February 23, 2021, 8:44am UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/17 "2021-02-23T08:44:18Z")

</div>

We have been suffering from this a lot. I guess it’s will be much better if control is given to the developer so that we have can have control what our app should behave rather than just a hack.

I find zoom dev are unhelpful most of the time, its on our end to find a workaround. I find really demotivated working with zoom sdk.

---

<div class="post-metadata">

**Author:** ![dario.mendoza](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dario.mendoza/32/22931_2.png) [@dario.mendoza](https://devforum.zoom.us/u/dario.mendoza)\
**Post date:** [February 23, 2021, 4:31pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/18 "2021-02-23T16:31:05Z")

</div>

Hi Max, that is the solution I suggest for the moment, let me know if it has worked for someone else.  
regards  
Darius

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [February 23, 2021, 10:31pm UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/19 "2021-02-23T22:31:57Z")

</div>

Hey @ankur.sharma,

Thank you for your feedback. I’m really sorry to hear that we haven’t been helpful. It’s our goal to make sure that using Zoom SDKs is as frictionless as possible.

If you have any issues, please do submit a forum topic going over any ongoing problems that you face and I’m happy to do whatever is necessary to help out. This might mean resolving the issue, working with our engineering team to add feature requests or to confirming if any of the changes are on our roadmap.

Thanks,  
Max

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [March 26, 2021, 8:32am UTC](https://devforum.zoom.us/t/how-do-i-close-the-window-after-leaveurl/43065/20 "2021-03-26T08:32:09Z")

</div>

Closed on March 26, 2021, 8:32am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
