Backspace button - radwindow

5 posts, 0 answers
  1. wnl
    wnl avatar
    106 posts
    Member since:
    Aug 2007

    Posted 26 Jan 2011 Link to this post

    Hi,
    I want to disable bacskapce (going to previous page) in radwindows.
    So I added js code:

    function getKey(keyStroke) {
                var t = window.event.srcElement.type;
                var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
                var keyString = String.fromCharCode(keyCode).toLowerCase();
                var leftArrowKey = 37;
                var backSpaceKey = 8;
                var escKey = 27;
                if (t && (t == 'text' || t == 'textarea' || t == 'file')) {
                    //do not cancel the event
                } else {
                    if ((window.event.altKey && window.event.keyCode == leftArrowKey) || (keyCode == escKey) || (keyCode == backSpaceKey)) {
                        alert(keyCode);
                        return false;
                    }
                }
            }

    <body onkeydown="getKey()">...
    but it doesn't work (alert is showing, but "false"doesn't stop going to previous page). Is any specific approach in radwindows to achieve the target?
    Thanks.
  2. wnl
    wnl avatar
    106 posts
    Member since:
    Aug 2007

    Posted 27 Jan 2011 Link to this post

    Sorry, I had a mistake in my js code. Now it works fine. 
    Please delete this topic.
  3. Amarendra Parab
    Amarendra Parab avatar
    5 posts
    Member since:
    Jan 2010

    Posted 20 Sep 2011 Link to this post

    What was the mistake in the js code that was corrected to make the code work.
  4. Bob
    Bob avatar
    6 posts
    Member since:
    Nov 2011

    Posted 04 Nov 2011 Link to this post

    What was the error you received in your JavaScript code that prevented the code from working??

    Thanks!
  5. wnl
    wnl avatar
    106 posts
    Member since:
    Aug 2007

    Posted 09 Nov 2011 Link to this post

    Hi, I don't remember now where I had a mistake but below I pasted my working code:

    function pageLoad() {
        var holder; 
        var element;
     
        /* IE uses this */
        if (typeof window.event != 'undefined') {
            document.onkeydown = function() {
                element = event.srcElement.tagName.toUpperCase();
                // alert(element);
                if (event.srcElement.tagName.toUpperCase() != 'INPUT' && event.srcElement.tagName.toUpperCase() != 'TEXTAREA') {
                    holder = event.keyCode;
                    // alert(holder);
                    return cancelBackspace(holder);
     
                }
                else {
                    if (event.srcElement.readOnly || event.srcElement.disabled) {
                        holder = event.keyCode;
                        return cancelBackspace(holder);
                    }
                }
            }
        }
    }

    function cancelBackspace(holder) {
        if (holder == 8) {
            return false;
        }
    }
Back to Top