Stopping ctl-click in IE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    #1

    Stopping ctl-click in IE

    I have a situation where I want to react to a ctrl-click on a <span> and
    it works in Netscape and Firefox browsers but in IE I have a problem.
    In IE I do catch the ctrl-click but IE also renders the span in inverse
    video, essentially selecting the item.

    Here is a short sample that demonstrates the issue:

    <html><head>
    <script type="text/javascript">

    function Clicked(evt){
    evt.cancelBubbl e=true;
    }

    </script></head>
    <body>
    <SPAN onClick="Clicke d(event);">clic k me</SPAN>
    </body></html>

    I thought the cancelBubble would prevent the event from triggering the
    selection from happening but I think that the ctrl-click selection
    happens before I get control.

    Is there a way to prevent the selection from being rendered on ctrl-
    click while still allowing my javascript to react to the event?

    browser versions used
    ie 6.0.2800
    firefox 0.9
    netscape 7.1
  • RobB

    #2
    Re: Stopping ctl-click in IE

    Dave wrote:[color=blue]
    > I have a situation where I want to react to a ctrl-click on a <span>[/color]
    and[color=blue]
    > it works in Netscape and Firefox browsers but in IE I have a problem.[/color]
    [color=blue]
    > In IE I do catch the ctrl-click but IE also renders the span in[/color]
    inverse[color=blue]
    > video, essentially selecting the item.
    >
    > Here is a short sample that demonstrates the issue:
    >
    > <html><head>
    > <script type="text/javascript">
    >
    > function Clicked(evt){
    > evt.cancelBubbl e=true;
    > }
    >
    > </script></head>
    > <body>
    > <SPAN onClick="Clicke d(event);">clic k me</SPAN>
    > </body></html>
    >
    > I thought the cancelBubble would prevent the event from triggering[/color]
    the[color=blue]
    > selection from happening but I think that the ctrl-click selection
    > happens before I get control.
    >
    > Is there a way to prevent the selection from being rendered on ctrl-
    > click while still allowing my javascript to react to the event?
    >
    > browser versions used
    > ie 6.0.2800
    > firefox 0.9
    > netscape 7.1[/color]

    Strictly MSIE:

    <span onselectstart=" return false;">...eeee eeesh!!</span>

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Stopping ctl-click in IE

      Dave <noemail@anyadd ressiown_invali d.com> writes:
      [color=blue]
      > <script type="text/javascript">
      >
      > function Clicked(evt){
      > evt.cancelBubbl e=true;
      > }
      >
      > </script></head>
      > <body>
      > <SPAN onClick="Clicke d(event);">clic k me</SPAN>
      > </body></html>
      >
      > I thought the cancelBubble would prevent the event from triggering the
      > selection from happening but I think that the ctrl-click selection
      > happens before I get control.[/color]

      Assigning true to "event.cancelBu bble" is the IE way of stopping further
      event handlers in the page, not stopping the default behavior of the
      click. To do that, assign false to "event.returnVa lue".

      A general function that works for standards compliant browsers as well:
      ---
      function clicked(evt){
      if (evt.preventDef ault) {
      evt.preventDefa ult(); // The W3C DOM way
      } else {
      evt.returnValue = false; // The IE way
      }
      }
      ---

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Dave

        #4
        Re: Stopping ctl-click in IE (version 2)

        In article <oechuqnj.fsf@h otpop.com>, lrn@hotpop.com says...[color=blue]
        >
        > A general function that works for standards compliant browsers as well:
        > ---
        > function clicked(evt){
        > if (evt.preventDef ault) {
        > evt.preventDefa ult(); // The W3C DOM way
        > } else {
        > evt.returnValue = false; // The IE way
        > }
        > }
        > ---[/color]

        Thanks for the response. It didn't work for me. I included the updated
        example below.

        I noticed one thing though. If I put an alert immediately before the
        evt.returnValue = false; I see that by the time the alert box is
        visible, "click me" is already highlighted. So I'm not sure how that
        event property could have an effect on the outcome.


        <html><head>
        <script type="text/javascript">

        function Clicked(evt){
        if (evt.preventDef ault) {
        evt.preventDefa ult(); // The W3C DOM way
        } else {
        evt.returnValue = false; // The IE way
        }
        evt.cancelBubbl e=true;
        }

        </script></head>
        <body>
        <SPAN onClick="Clicke d(event);">clic k me</SPAN>
        </body></html>

        Comment

        • Dave

          #5
          Re: Stopping ctl-click in IE

          In article <1113504652.247 641.29450@g14g2 000cwa.googlegr oups.com>,
          ferndoc9@hotmai l.com says...[color=blue]
          > Strictly MSIE:
          >
          > <span onselectstart=" return false;">...eeee eeesh!!</span>
          >
          >[/color]

          That's too bad it's a MSIE specific solution, but it did work.

          Thanks!

          Comment

          • DU

            #6
            Re: Stopping ctl-click in IE

            Lasse Reichstein Nielsen wrote:
            [color=blue]
            > ---
            > function clicked(evt){
            > if (evt.preventDef ault) {
            > evt.preventDefa ult(); // The W3C DOM way
            > } else {[/color]

            Shouldn't that be else if(window.event )
            {event.returnVa lue = false;};
            [color=blue]
            > evt.returnValue = false; // The IE way
            > }
            > }[/color]

            DU
            --
            The site said to use Internet Explorer 5 or better... so I switched to
            Mozilla 1.7.6 :)

            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: Stopping ctl-click in IE

              DU <drunclear@hotN OSPAMmail.com> writes:
              [color=blue]
              > Lasse Reichstein Nielsen wrote:
              >[color=green]
              >> ---
              >> function clicked(evt){ if (evt.preventDef ault) {
              >> evt.preventDefa ult(); // The W3C DOM way
              >> } else {[/color]
              >
              > Shouldn't that be else if(window.event )
              > {event.returnVa lue = false;};[/color]

              In this scenario, the function was called from an HTML event
              handler:
              <blah onblah="clicked (event); .. ">
              so "evt" does refer to the global event handler in IE too.

              It should probably be:

              <blah onblah="return clicked(event); ">
              ....
              function clicked(evt) {
              ...
              if (evt.preventDef ault) {
              evt.preventDefa ult();
              } else {
              evt.returnValue = false; // can't hurt
              return false;
              }
              }

              .... to handler thr likes of Netscape 4.
              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              Working...