# Confirm before closing lister window

**URL:** https://resource.dopus.com/t/confirm-before-closing-lister-window/34600
**Category:** Buttons/Scripts
**Tags:** script, jscript, events
**Created:** [February 9, 2020, 4:07pm UTC](https://resource.dopus.com/t/confirm-before-closing-lister-window/34600 "2020-02-09T16:07:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)
#### Post date: [February 9, 2020, 4:07pm UTC](https://resource.dopus.com/t/confirm-before-closing-lister-window/34600/1 "2020-02-09T16:07:15Z")

</div>

### Overview

This simple script adds a confirmation dialog when you click the lister window's close button, allowing you to confirm or cancel the closure.

![image](https://resource.dopus.com/uploads/default/original/3X/b/4/b48e76cf1c112a936015d7408c10e97b5d10d07a.png)

You can hold a qualifier key (shift, alt, ctrl) while clicking the close button to suppress the confirmation.

If Windows or Opus are being shutdown entirely, the confirmation will not appear, so that it does not delay shutting down the machine.

### Install

- Download [CloseConfirm.js.txt](https://resource.dopus.com/uploads/short-url/c10u6Uklm5cqt27Eyf7QJaGukOl.txt) (948 Bytes)
- Go to **Preferences / Toolbars / Scripts**.
- Drag the script into the list and click **OK**.

### History

#### v1.0 (09/Feb/2020)

- Initial version.

### Script Code

The download above is reproduced below, to help people browsing for scripting techniques:

```javascript
function OnInit(initData)
{
	initData.name = "CloseConfirm";
	initData.version = "1.0";
	initData.copyright = "(c) 2020 Leo Davidson";
	initData.url = "https://resource.dopus.com/t/confirm-before-closing-lister-window/34600";
	initData.desc = "";
	initData.default_enable = true;
	initData.min_version = "12.0";
}

function OnCloseLister(closeListerData)
{
	// Is Opus, or Windows, being shutdown completely?
	if (closeListerData.shutdown)
	{
		return false; // Don't block closing the window.
	}

	// Are any qualifier keys held down?
	if (closeListerData.qualifiers != "none")
	{
		return false; // Don't block closing the window.
	}
	
	var dlg = closeListerData.lister.Dlg();
	
	var choice = dlg.Request("Are you sure you want to close the window?", "Close|Cancel", "Close Lister");
	
	if (choice == 1)
	{
		return false; // Don't block closing the window.
	}

	return true; // Block closing the window.
}

```

---

<div class="post-metadata">

### Author: ![tortilladude](https://resource.dopus.com/letter_avatar_proxy/v4/letter/t/aeb1de/32.png) [@tortilladude](https://resource.dopus.com/u/tortilladude)
#### Post date: [February 16, 2020, 5:38am UTC](https://resource.dopus.com/t/confirm-before-closing-lister-window/34600/2 "2020-02-16T05:38:49Z")

</div>

Awesome! Thanks! Somitimes i misclick, so this solves that 😃
