This is a migrated thread and some comments may be shown as answers.

Slight problem with jQuery and keypresses in a RadWindow

2 Answers 22 Views
Window
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 05 Dec 2012, 06:26 PM
I have an extremely simple radwindow, called as follows: 
     var oWnd = window.radopen(url, "title");
     oWnd.show();

Once in the window I want to be able to close it simply by hitting the Esc key.  

I have this code, essentially pieced together from various threads.  :
The code below works, but only if I click within the body of the RadWindow first or, if on load, I set the focus to a control within the body.

 Anything particularly wrong with this?

   $(window).ready(function () {
            // Handler for .ready() called.
            $(window).keydown(function (e) {              
                // ESCAPE key pressed
                if (e.keyCode == 27) {                  
                    var oWnd = GetRadWindow();
                    oWnd.close();
                }
            });
   });

function closeWindow() {
            var oWnd = GetRadWindow();
            oWnd.close();
        }
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow;
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow;
            return oWindow;
        }

2 Answers, 1 is accepted

Sort by
0
Accepted
Kevin
Top achievements
Rank 2
answered on 05 Dec 2012, 09:31 PM
Hey Boris,

If you have the latest version of the controls you can just use the Shortcuts collection of the RadWindow.

Here's a demo that shows you how to do it:

http://demos.telerik.com/aspnet-ajax/window/examples/keyboardsupport/defaultcs.aspx


Hope that helps.
0
Boris
Top achievements
Rank 1
answered on 05 Dec 2012, 10:01 PM
Thanks.

Now to try and do something similar with RadGrid template popups...
Tags
Window
Asked by
Boris
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Boris
Top achievements
Rank 1
Share this question
or