I've been working on this task for a while now and can't get it work. Basically I have this window that I'm able to toggle when clicking on **"toggle button"**, but I'm trying to close window when user clicks anywhere outside the window and I'm not having any luck with it. Can anyone point me in the right direction? I found a solution but it's uses ExtJS 6, and I'm using version 4.1. Thanks a lot in a advance!

**Here's my code:**

```
button.on('click', function() {
if (myWindow.isVisible()) {
    myWindow.hide();

  } else {
    myWindow.show();
    myWindow.alignTo(Ext.getBody(), "tr-tr", [-10, 10]);
  }
 }, this);

}

```

Here's [**LIVE DEMO**](http://jsfiddle.net/henryDev/9satfr40/17/)

Now, I found this code that works but it uses Extjs 6.

```
Ext.create('Ext.window.Window', {
float: true,
width: 300,
height: 200,
listeners: {
    focusleave: function (cmp) {
        cmp.close();
    }
},
renderTo: Ext.getBody()
}).show();

```

This is the [**LINK**](https://fiddle.sencha.com/#view/editor&fiddle/2ju9) to this version using Extjs 6