Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    stop key events propagation to browser

    Hi,
    I need handle special keys (F1-F12, Esc, ...). But many of this keys are handled internaly by the browser (search, refresh, help). If I press F1 i get event from KeyPressEvent, but browser open the window with help too. I find javascript function, that can stop propagation of the event to the browser:
    [CODE]
    <script>
    function cancelEvent(event) {

    if (event.returnValue != null) {
    event.keyCode = 0;
    event.returnValue = false;
    }
    if (event.cancelBubble != null) event.cancelBubble = true;
    if (event.stopPropagation) event.stopPropagation();
    if (event.preventDefault) event.preventDefault();
    return false;

    }
    document.onhelp = function () {return false;};
    </script>
    [\CODE]

    It works corectly in IE and firefox.

    Is it possible to stop propagation in smartGWT in KeyPressHandler in onKeyPress method. I try call the abov function, but I'm not able to get nativ browser event form KeyPressEvent.

    Thanks Pavel

    #2
    ahoj pavle

    ahoj,

    I'm also interested in this - did you eventually find a solution to this?

    -- petr

    Comment


      #3
      any solution?

      I have the same problem ...

      any comment?

      Comment


        #4
        Here are the response:

        For IE, FF and Chrome:

        Code:
        Define this function, and it has to be called in the body tag !!!! (<body ... onkeydown="return capturaTeclasFuncion(event)" >)
        
        function capturaTeclasFuncion(e){
        
            var tecla = (document.all)?e.keyCode:e.which;
            var pista = '';
        
            if (tecla >= 112 && tecla <= 123){
        
               // Para FF, Chrome
               if (e.preventDefault) {
                    pista = 'preventDefault';
                    e.preventDefault();
               } else {
               // Para IE
                  pista = 'x IE ';
                  if (window.event && (window.event.keyCode >= 113 && window.event.keyCode <= 123)) {
                      window.event.keyCode = 9999;
                  }
                  if (window.event && window.event.keyCode == 9999) {
                    // try to cancel the backspace
                    window.event.cancelBubble = true;
                    window.event.returnValue = false;
                  }
               }
          
                return false;
        
            } else return true;
        }
        
        If you are using IE, to disable F1 (help) do not forget to write: 
        
        document.onhelp = function() {
                    return false; // necessary for cancel original F1 event
        }
        That is all !!!!
        Last edited by rafa1970; 25 Mar 2010, 08:06.

        Comment

        Working...
        X