# Restrict the Positioning of the Window

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Progress® Kendo UI® Window for jQuery</td>
 </tr>
 <tr>
  <td>Operating System</td>
  <td>Windows 10 64bit</td>
 </tr>
 <tr>
  <td>Visual Studio Version</td>
  <td>Visual Studio 2017</td>
 </tr>
 <tr>
  <td>Preferred Language</td>
  <td>JavaScript</td>
 </tr>
</table>

## Description

How can I restrict the movement of a Kendo UI Window to a certain area?

## Solution

The example below demonstrates how to achieve the desired scenario.

```dojo
    <div id="window">
      Window content
    </div>
    <script>
      $(function() {

        function onWindowDrag (e) {
          var windowWrapper = winObject.wrapper,
              windowPosition = windowWrapper.offset(),
              shouldOverridePosition = false,
              newTop = windowPosition.top,
              newLeft = windowPosition.left;

          if (windowPosition.top > 50 || windowPosition.top < 0) {
            shouldOverridePosition = true;
            newTop = 50;
          }

          if (windowPosition.left > 50 || windowPosition.left < 0) {
            shouldOverridePosition = true;
            newLeft = 50;
          }

          if (shouldOverridePosition) {
            winObject.setOptions({
              position: {
                top: newTop,
                left: newLeft
              }
            });
          }
        }

        var winObject = $("#window").kendoWindow({
          width: 600,
          height: 300,
          position: {
            top: 0,
            left: 0
          },
          title: "Kendo UI Window",
          dragend: onWindowDrag
        }).data("kendoWindow");
      });
    </script>
```

## See Also

* [Window JavaScript API Reference](https://www.telerik.com/kendo-jquery-ui/documentation/api/ui/window)
* [Add Close Button inside Modal Windows](https://www.telerik.com/kendo-jquery-ui/documentation/knowledge-base/add-close-button)
* [Create Confirmation Dialog via Promises](https://www.telerik.com/kendo-jquery-ui/documentation/knowledge-base/confirmation-dialog-promise)
* [Initialize the Grid](https://www.telerik.com/kendo-jquery-ui/documentation/knowledge-base/initiliaze-grid-in-window)
* [Post to Iframe](https://www.telerik.com/kendo-jquery-ui/documentation/knowledge-base/post-to-iframe)
