IE Not Stopping Default Event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • blaine@worldweb.com

    IE Not Stopping Default Event

    Hello,

    I'm currently overriding function keys (F1 to F4) to perform other
    actions. In order to do this the default popup windows of Help (F1),
    Seach(F3) etc must be turned off. In FF it's easy enought to do using
    the preventDefault and stopPropagation event functions.

    IE's equivalent is supposed to be cancelBubble and returnValue,
    however I can not seem to get them to stop no matter what I try.

    Can someone please point out my error? The test code is below.

    ------
    var classKeyPressOv erride = function(){}
    classKeyPressOv erride.prototyp e.toString = function(){ return " Class
    Key Press Override "; }
    classKeyPressOv erride.prototyp e.attachListene r = function( type,
    functionCode ){
    //Register the listener
    var obj = window.document ;
    if ('addEventListe ner' in obj) {
    obj.addEventLis tener( type, functionCode, true);
    } else if ('attachEvent' in obj) {
    obj.attachEvent ('on' + type, functionCode );
    } else {
    alert("Could not add listener");
    }
    }


    //Create an instance and add attach a lister tpe of keydown
    var classKP = new classKeyPressOv erride();

    classKP.attachL istener('keydow n', function(event) {
    var ev = event || window.event;

    var keyCode = ev.keyCode || ev.which;
    alert("aatrying " + keyCode);
    var fKeyPressed = false;

    //IE won't like the regular ev.DOM_VK_F1 so use keyCode values.
    if (keyCode == 112) {
    fKeyPressed = true;
    alert("ev F1 Pressed");
    }else if (keyCode == 113) {
    fKeyPressed = true;
    alert("F2 Pressed");
    }else if (keyCode == 114) {
    fKeyPressed = true;
    alert("F3 Pressed");
    }else if (keyCode == 115) {
    fKeyPressed = true;
    alert("F4 Pressed");
    }

    if (fKeyPressed){
    //Prevent help menu and other default F1 key functions
    if ('stopPropagati on' in ev) {
    ev.stopPropagat ion();
    ev.preventDefau lt();
    }else{
    // Trying to stop the popup windows in IE
    //Does not seem to work...
    ev.cancelBubble = true;
    ev.returnValue = false;
    }
    }

    }
    );

  • =?ISO-8859-1?Q?G=E9rard_Talbot?=

    #2
    Re: IE Not Stopping Default Event

    blaine@worldweb .com wrote :
    Hello,
    >
    I'm currently overriding function keys (F1 to F4) to perform other
    actions.
    Wow! How nice of you to do this for/to your users.
    In order to do this the default popup windows of Help (F1),
    Seach(F3) etc must be turned off.
    Wow! The end must justify the means.
    In FF it's easy enought to do using
    the preventDefault and stopPropagation event functions.
    Maybe your code have succeeded in defeating the general purpose of a
    sound user-author relationship where the webpage should not alienate the
    user. There is such a thing as "do not alienate your users even though
    you can/could" guideline, "do not over-power, over-control the users'
    control over basic functions, keys," etc.

    What's next? Can you remotedly over-ride the On/Off switch button on the
    PC of users?
    IE's equivalent is supposed to be cancelBubble and returnValue,
    Overriding the F1 key is like overriding the 911 phone number and what
    it means to a wide majority of normal, reasonable people. Your code may
    have succeeded in a global self-defeating strategy.

    Gérard
    --
    Using Web Standards in your Web Pages (Updated Dec. 2006)
    The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.

    Comment

    • blaine@worldweb.com

      #3
      Re: IE Not Stopping Default Event

      Hey Gérard,

      Thanks for your concern.

      If you would have thought about it a little longer you may have
      realized that this if for a web application that the general public
      does not have access to.

      Since users a trained to press the K-Keys for help. It makes perfect
      sense to override the Help menu of the browser with the Help Menu of
      the application.

      Sincerely,
      Blaine



      On Apr 5, 3:45 pm, Gérard Talbot <newsblahgr...@ gtalbot.orgwrot e:
      bla...@worldweb .com wrote :
      >
      Hello,
      >
      I'm currently overriding function keys (F1 to F4) to perform other
      actions.
      >
      Wow! How nice of you to do this for/to your users.
      >
      In order to do this the default popup windows of Help (F1),
      Seach(F3) etc must be turned off.
      >
      Wow! The end must justify the means.
      >
      In FF it's easy enought to do using
      the preventDefault and stopPropagation event functions.
      >
      Maybe your code have succeeded in defeating the general purpose of a
      sound user-author relationship where the webpage should not alienate the
      user. There is such a thing as "do not alienate your users even though
      you can/could" guideline, "do not over-power, over-control the users'
      control over basic functions, keys," etc.
      >
      What's next? Can you remotedly over-ride the On/Off switch button on the
      PC of users?
      >
      IE's equivalent is supposed to be cancelBubble and returnValue,
      >
      Overriding the F1 key is like overriding the 911 phone number and what
      it means to a wide majority of normal, reasonable people. Your code may
      have succeeded in a global self-defeating strategy.
      >
      Gérard
      --
      Using Web Standards in your Web Pages (Updated Dec. 2006)http://developer..mozilla.org/en/doc...s_in_your_Web_...

      Comment

      • Lee

        #4
        Re: IE Not Stopping Default Event

        blaine@worldweb .com said:
        >
        >Hey G=E9rard,
        >
        >Thanks for your concern.
        >
        >If you would have thought about it a little longer you may have
        >realized that this if for a web application that the general public
        >does not have access to.
        What clues did you provide that might have helped anyone to
        realize that? The vast majority of posts in this newsgroup
        are about internet sites, putting the onus on you few others
        to identify your unusual situation.

        It doesn't make sense to over-ride browser functionality.
        Even if your current users are used to some legacy system,
        it makes much more sense to have them adapt to web browser
        standards than to try to pervert the browser to fit them.


        --

        Comment

        • =?ISO-8859-1?Q?G=E9rard_Talbot?=

          #5
          Re: IE Not Stopping Default Event

          blaine@worldweb .com wrote :
          Hey Gérard,
          >
          Thanks for your concern.
          >
          Thank you for not top-posting in comp.lang.javas cript newsgroup.
          If you would have thought about it a little longer you may have
          realized that this if for a web application that the general public
          does not have access to.
          Are you actually saying that you did not think of including such vital
          info in your original post or are you saying that you assumed that
          readers of your post would have been able (or should be able) to read
          your mind over the internet, figure out your intentions and missing
          information and then establish that your intentions are sound, fair,
          legitimate, level-headed and that your application requirements are all
          balanced, sensible and above any reproach?
          Since users a trained to press the K-Keys for help.
          I read your post several times and still don't understand how or why the
          F1 key should be replaced by the "K-Keys" for help or why it is a good
          idea to replace the F1 key in an intranet application with the "K-keys".

          Maybe one day there will be an original urbanist who will redesign color
          for street lights and he will use purple or gray for stop instead of red
          and he will choose yellow for going across street intersection instead
          of green and such colors will only apply to his town, not outside such town.
          It makes perfect
          sense to override the Help menu of the browser with the Help Menu of
          the application.
          Your words up there. Not mine.
          Sincerely,
          Blaine
          Fair enough. Good luck.

          Gérard
          --
          Using Web Standards in your Web Pages (Updated Dec. 2006)
          The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.

          Comment

          • blaine@worldweb.com

            #6
            Re: IE Not Stopping Default Event

            I just wanted to post the solution for anyone that is interested.

            1) If you want to override the 'F1' button in IE you need to attach an
            event listener to stop
            the default action.
            classKP.attachL istener('help', classKP.stopPro pagation );

            2) In IE cancelBubble and returnValue were not stopping the default
            actions as specified in the docs, setting the keyCode to 0 then
            running the actions stops all the defaults
            ev.keyCode = 0;


            Below is a working example.


            var classKeyPressOv erride = function(){}
            classKeyPressOv erride.prototyp e.toString = function(){ return " Class
            Key Press Override "; }
            classKeyPressOv erride.prototyp e.attachListene r = function( type,
            functionCode ){
            //Register the listener

            var obj = window.document ;
            obj.eventParent = this;
            if ('addEventListe ner' in obj) {
            obj.addEventLis tener( type, functionCode, true);

            } else if ('attachEvent' in obj) {
            obj.attachEvent ('on' + type, functionCode );
            } else {
            alert("Could not add listener");
            }
            }
            classKeyPressOv erride.prototyp e.stopPropagati on = function(ev){
            if ('stopPropagati on' in ev) {
            ev.stopPropagat ion();
            ev.preventDefau lt();
            }else{
            ev.keyCode = 0;
            ev.cancelBubble = true;
            ev.returnValue = false;
            }
            }

            //Create an instance and add attach a lister tpe of keydown
            var classKP = new classKeyPressOv erride();
            classKP.attachL istener('help', classKP.stopPro pagation );
            classKP.attachL istener('keydow n', function(event, parentClass){
            var ev = event || window.event;

            var keyCode = ev.keyCode || ev.which;
            var fKeyPressed = false;

            //ev.DOM_VK_F1
            if (keyCode == 112) {
            fKeyPressed = true;
            //alert("ev F1 Pressed");
            }else if (keyCode == 113) {
            fKeyPressed = true;
            //alert("F2 Pressed");
            }else if (keyCode == 114) {
            fKeyPressed = true;
            //alert("F3 Pressed");
            }else if (keyCode == 115) {
            fKeyPressed = true;
            //alert("F4 Pressed");
            }

            if (fKeyPressed == true){
            this.eventParen t.stopPropagati on(event);
            }

            }
            );




            On Apr 7, 10:35 pm, Gérard Talbot <newsblahgr...@ gtalbot.orgwrot e:
            bla...@worldweb .com wrote :
            >
            Hey Gérard,
            >
            Thanks for your concern.
            >
            Thank you for not top-posting in comp.lang.javas cript newsgroup.
            >
            If you would have thought about it a little longer you may have
            realized that this if for a web application that the general public
            does not have access to.
            >
            Are you actually saying that you did not think of including such vital
            info in your original post or are you saying that you assumed that
            readers of your post would have been able (or should be able) to read
            your mind over the internet, figure out your intentions and missing
            information and then establish that your intentions are sound, fair,
            legitimate, level-headed and that your application requirements are all
            balanced, sensible and above any reproach?
            >
            Since users a trained to press the K-Keys for help.
            >
            I read your post several times and still don't understand how or why the
            F1 key should be replaced by the "K-Keys" for help or why it is a good
            idea to replace the F1 key in an intranet application with the "K-keys".
            >
            Maybe one day there will be an original urbanist who will redesign color
            for street lights and he will use purple or gray for stop instead of red
            and he will choose yellow for going across street intersection instead
            of green and such colors will only apply to his town, not outside such town.
            >
            It makes perfect
            sense to override the Help menu of the browser with the Help Menu of
            the application.
            >
            Your words up there. Not mine.
            >
            Sincerely,
            Blaine
            >
            Fair enough. Good luck.
            >
            Gérard
            --
            Using Web Standards in your Web Pages (Updated Dec. 2006)http://developer..mozilla.org/en/doc...s_in_your_Web_...

            Comment

            • blaine@worldweb.com

              #7
              Re: IE Not Stopping Default Event

              Ups I problem with the code above..

              The line
              this.eventParen t.stopPropagati on(event)
              should be:
              classKP.stopPro pagation(event) ;



              var classKeyPressOv erride = function(){}
              classKeyPressOv erride.prototyp e.toString = function(){ return " Class
              Key Press Override "; }
              classKeyPressOv erride.prototyp e.attachListene r = function( type,
              functionCode ){
              //Register the listener

              var obj = window.document ;

              if ('addEventListe ner' in obj) {
              obj.addEventLis tener( type, functionCode, true);

              } else if ('attachEvent' in obj) {
              obj.attachEvent ('on' + type, functionCode );
              } else {
              alert("Could not add listener");
              }
              }

              classKeyPressOv erride.prototyp e.addListener = function(obj, evt, fun,
              b) {
              var eventPhase = (typeof(b)=='bo olean') ? b : false;

              if ('addEventListe ner' in obj) {
              obj.addEventLis tener(evt, fun, eventPhase);
              } else if ('attachEvent' in obj) {
              obj.attachEvent (evt, fun);
              } else {
              alert("Could not add listener");
              }
              }

              classKeyPressOv erride.prototyp e.stopPropagati on = function(ev){
              if ('stopPropagati on' in ev) {
              ev.stopPropagat ion();
              ev.preventDefau lt();
              }else{
              ev.keyCode = 0;
              ev.cancelBubble = true;
              ev.returnValue = false;
              }
              }

              //Create an instance and add attach a lister tpe of keydown
              var classKP = new classKeyPressOv erride();
              classKP.attachL istener('help', classKP.stopPro pagation );
              classKP.attachL istener('keydow n', function(event) {
              var ev = event || window.event;

              var keyCode = ev.keyCode || ev.which;
              var fKeyPressed = false;

              //ev.DOM_VK_F1
              if (keyCode == 112) {
              fKeyPressed = true;
              //alert("ev F1 Pressed");
              }else if (keyCode == 113) {
              fKeyPressed = true;
              //alert("F2 Pressed");
              }else if (keyCode == 114) {
              fKeyPressed = true;
              //alert("F3 Pressed");
              }else if (keyCode == 115) {
              fKeyPressed = true;
              //alert("F4 Pressed");
              }

              if (fKeyPressed == true){
              //new classKeyPressOv erride().stopPr opagation(event );

              //Use the variable name of the class instance
              //Since it is within the scopt of this function code
              // "this" and "parent" refer to the object that the key lister is
              run on ie window.document
              classKP.stopPro pagation(event) ;
              }
              }
              );




              On Apr 9, 11:04 am, "bla...@worldwe b.com" <bla...@worldwe b.comwrote:
              I just wanted to post the solution for anyone that is interested.
              >
              1) If you want to override the 'F1' button in IE you need to attach an
              event listener to stop
              the default action.
              classKP.attachL istener('help', classKP.stopPro pagation );
              >
              2) In IE cancelBubble and returnValue were not stopping the default
              actions as specified in the docs, setting the keyCode to 0 then
              running the actions stops all the defaults
              ev.keyCode = 0;
              >
              Below is a working example.
              >
              var classKeyPressOv erride = function(){}
              classKeyPressOv erride.prototyp e.toString = function(){ return " Class
              Key Press Override "; }
              classKeyPressOv erride.prototyp e.attachListene r = function( type,
              functionCode ){
              //Register the listener
              >
              var obj = window.document ;
              obj.eventParent = this;
              if ('addEventListe ner' in obj) {
              obj.addEventLis tener( type, functionCode, true);
              >
              } else if ('attachEvent' in obj) {
              obj.attachEvent ('on' + type, functionCode );
              } else {
              alert("Could not add listener");
              }}
              >
              classKeyPressOv erride.prototyp e.stopPropagati on = function(ev){
              if ('stopPropagati on' in ev) {
              ev.stopPropagat ion();
              ev.preventDefau lt();
              }else{
              ev.keyCode = 0;
              ev.cancelBubble = true;
              ev.returnValue = false;
              }
              >
              }
              >
              //Create an instance and add attach a lister tpe of keydown
              var classKP = new classKeyPressOv erride();
              classKP.attachL istener('help', classKP.stopPro pagation );
              classKP.attachL istener('keydow n', function(event, parentClass){
              var ev = event || window.event;
              >
              var keyCode = ev.keyCode || ev.which;
              var fKeyPressed = false;
              >
              //ev.DOM_VK_F1
              if (keyCode == 112) {
              fKeyPressed = true;
              //alert("ev F1 Pressed");
              }else if (keyCode == 113) {
              fKeyPressed = true;
              //alert("F2 Pressed");
              }else if (keyCode == 114) {
              fKeyPressed = true;
              //alert("F3 Pressed");
              }else if (keyCode == 115) {
              fKeyPressed = true;
              //alert("F4 Pressed");
              }
              >
              if (fKeyPressed == true){
              this.eventParen t.stopPropagati on(event);
              }
              >
              }
              >
              );
              >
              On Apr 7, 10:35 pm, Gérard Talbot <newsblahgr...@ gtalbot.orgwrot e:
              >
              bla...@worldweb .com wrote :
              >
              Hey Gérard,
              >
              Thanks for your concern.
              >
              Thank you for not top-posting in comp.lang.javas cript newsgroup.
              >
              If you would have thought about it a little longer you may have
              realized that this if for a web application that the general public
              does not have access to.
              >
              Are you actually saying that you did not think of including such vital
              info in your original post or are you saying that you assumed that
              readers of your post would have been able (or should be able) to read
              your mind over the internet, figure out your intentions and missing
              information and then establish that your intentions are sound, fair,
              legitimate, level-headed and that your application requirements are all
              balanced, sensible and above any reproach?
              >
              Since users a trained to press the K-Keys for help.
              >
              I read your post several times and still don't understand how or why the
              F1 key should be replaced by the "K-Keys" for help or why it is a good
              idea to replace the F1 key in an intranet application with the "K-keys".
              >
              Maybe one day there will be an original urbanist who will redesign color
              for street lights and he will use purple or gray for stop instead of red
              and he will choose yellow for going across street intersection instead
              of green and such colors will only apply to his town, not outside such town.
              >
              It makes perfect
              sense to override the Help menu of the browser with the Help Menu of
              the application.
              >
              Your words up there. Not mine.
              >
              Sincerely,
              Blaine
              >
              Fair enough. Good luck.
              >
              Gérard
              --
              Using Web Standards in your Web Pages (Updated Dec. 2006)http://developer.mozilla.org/en/docs...s_in_your_Web_...

              Comment

              Working...