question about captureEvents

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

    #1

    question about captureEvents

    Hi,

    With this code, I thought that any 'click' with the mouse would be captured
    on the window level and nothing would happen, but a click on the button
    triggers nevertheless the function hit(). Why is it not directed to the
    function IgnoreEvents instead of the function hit?
    ....
    <script>
    window.top.capt ureEvents(Event .CLICK)
    window.top.oncl ick=IgnoreEvent s

    function IgnoreEvents(e)
    { return false }

    function hit()
    { alert('hit') }
    </script>

    INPUT TYPE="button" onClick="hit()"
    ....

    Thanks for your explanation
    Dave


  • Martin Honnen

    #2
    Re: question about captureEvents



    Dave wrote:[color=blue]
    > Hi,
    >
    > With this code, I thought that any 'click' with the mouse would be captured
    > on the window level and nothing would happen, but a click on the button
    > triggers nevertheless the function hit(). Why is it not directed to the
    > function IgnoreEvents instead of the function hit?
    > ...
    > <script>
    > window.top.capt ureEvents(Event .CLICK)
    > window.top.oncl ick=IgnoreEvent s
    >
    > function IgnoreEvents(e)
    > { return false }
    >
    > function hit()
    > { alert('hit') }
    > </script>
    >
    > INPUT TYPE="button" onClick="hit()"
    > ...
    >
    > Thanks for your explanation[/color]

    captureEvents is part of the NN4 event model, and with NN4 I am sure you
    can click the button as much as you want, it doesn't fire its onclick
    handler:

    <html>
    <head>
    <title>NN4 captureEvents</title>
    <script type="text/javascript">
    if (document.layer s) {
    window.captureE vents(Event.CLI CK);
    window.onclick = function (evt) {
    return false;
    }
    }
    </script>
    </head>
    <body>
    <form>
    <input type="button" value="button"
    onclick="alert( event.type);">
    </form>
    </body>
    </html>

    I guess you are trying with Netscape 6/7 or Mozilla which unfortunately
    has window.captureE vents as a function in its browser object model but
    this doesn't do anything.
    If you want to capture events with Netscape 6/7 or Mozilla use
    window.addEvent Listener('event name', eventHandler, true)
    as in

    <html>
    <head>
    <title>NN4 captureEvents</title>
    <script type="text/javascript">
    if (document.layer s) {
    window.captureE vents(Event.CLI CK);
    window.onclick = function (evt) {
    return false;
    }
    }
    else if (window.addEven tListener) {
    window.addEvent Listener('click ',
    function (evt) {
    if (evt.stopPropag ation) {
    evt.stopPropaga tion();
    return false;
    }
    },
    true
    );
    }
    </script>
    </head>
    <body>
    <form>
    <input type="button" value="button"
    onclick="alert( event.type);">
    </form>
    </body>
    </html>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Dave

      #3
      Re: question about captureEvents

      Thanks again, it works with NN 7.
      But i still can click on the menu and other buttons of the browser. Is it
      not possible to make this impossible?

      Dave


      "Martin Honnen" <Martin.Honnen@ t-online.de> schreef in bericht
      news:3F44F697.9 050905@t-online.de...[color=blue]
      >
      >
      > Dave wrote:[color=green]
      > > Hi,
      > >
      > > With this code, I thought that any 'click' with the mouse would be[/color][/color]
      captured[color=blue][color=green]
      > > on the window level and nothing would happen, but a click on the button
      > > triggers nevertheless the function hit(). Why is it not directed to the
      > > function IgnoreEvents instead of the function hit?
      > > ...
      > > <script>
      > > window.top.capt ureEvents(Event .CLICK)
      > > window.top.oncl ick=IgnoreEvent s
      > >
      > > function IgnoreEvents(e)
      > > { return false }
      > >
      > > function hit()
      > > { alert('hit') }
      > > </script>
      > >
      > > INPUT TYPE="button" onClick="hit()"
      > > ...
      > >
      > > Thanks for your explanation[/color]
      >
      > captureEvents is part of the NN4 event model, and with NN4 I am sure you
      > can click the button as much as you want, it doesn't fire its onclick
      > handler:
      >
      > <html>
      > <head>
      > <title>NN4 captureEvents</title>
      > <script type="text/javascript">
      > if (document.layer s) {
      > window.captureE vents(Event.CLI CK);
      > window.onclick = function (evt) {
      > return false;
      > }
      > }
      > </script>
      > </head>
      > <body>
      > <form>
      > <input type="button" value="button"
      > onclick="alert( event.type);">
      > </form>
      > </body>
      > </html>
      >
      > I guess you are trying with Netscape 6/7 or Mozilla which unfortunately
      > has window.captureE vents as a function in its browser object model but
      > this doesn't do anything.
      > If you want to capture events with Netscape 6/7 or Mozilla use
      > window.addEvent Listener('event name', eventHandler, true)
      > as in
      >
      > <html>
      > <head>
      > <title>NN4 captureEvents</title>
      > <script type="text/javascript">
      > if (document.layer s) {
      > window.captureE vents(Event.CLI CK);
      > window.onclick = function (evt) {
      > return false;
      > }
      > }
      > else if (window.addEven tListener) {
      > window.addEvent Listener('click ',
      > function (evt) {
      > if (evt.stopPropag ation) {
      > evt.stopPropaga tion();
      > return false;
      > }
      > },
      > true
      > );
      > }
      > </script>
      > </head>
      > <body>
      > <form>
      > <input type="button" value="button"
      > onclick="alert( event.type);">
      > </form>
      > </body>
      > </html>
      >
      > --
      >
      > Martin Honnen
      > http://JavaScript.FAQTs.com/
      >[/color]


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: question about captureEvents

        "Dave" <no@dsfg.vb> writes:
        [color=blue]
        > But i still can click on the menu and other buttons of the browser. Is it
        > not possible to make this impossible?[/color]

        Generally, no. I wouldn't want to use a browser where it is possible,
        and most users would find it highly annoying anyway.
        The safest is to just forget the idea.

        Please don't top post.
        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Dave

          #5
          Re: question about captureEvents

          Look at those very similar scripts: with the first, using a window, every
          click of the mouse (even menus and buttons) is blocked as long as the
          created window is open. With the second script, using a button, it should be
          the same as long as the value of the button is not 'changed', but it doesn't
          work. I can click anywhere.
          If you could tell me why, it would be great (both scripts running with NN
          7). Thanks in advance.
          Dave

          script 1:

          <INPUT TYPE="button" value="block everything" onclick="start( )">
          <INPUT TYPE="button" VALUE="anything " onclick="myfunc tion()">
          <SCRIPT>
          var winModalWindow

          function start()
          {
          window.top.capt ureEvents(Event .CLICK|Event.FO CUS)
          window.top.oncl ick="return false"
          window.top.onfo cus=HandleFocus
          xx="left=500,to p=300,dependent =yes"
          winModalWindow = window.open("wi n2.htm","",xx)
          winModalWindow. focus()
          }


          function HandleFocus()
          {
          if (winModalWindow )
          {
          if (!winModalWindo w.closed)
          {
          winModalWindow. focus()
          }
          else
          {
          window.top.rele aseEvents (Event.CLICK|Ev ent.FOCUS)
          window.top.oncl ick = ""
          }
          }
          return false
          }

          function myfunction()
          {
          alert("ok")
          }
          </script>



          script 2:

          <INPUT id="bu" TYPE="button" VALUE="should block" onclick="start( )">
          <INPUT TYPE="button" VALUE="anything " onclick="myfunc tion()">
          <INPUT TYPE="button" VALUE="changed" onclick="change ()">

          <SCRIPT>
          var winModalWindow

          function start()
          {
          window.top.capt ureEvents(Event .CLICK|Event.FO CUS)
          window.top.oncl ick="return false"
          window.top.onfo cus=HandleFocus
          winModalWindow = document.getEle mentById("bu")
          winModalWindow. focus()
          }

          function HandleFocus()
          {
          if (winModalWindow )
          {
          if (! (winModalWindow .value=="change d"))
          winModalWindow. focus()
          else
          {
          window.top.rele aseEvents (Event.CLICK|Ev ent.FOCUS)
          window.top.oncl ick = ""
          }
          }
          return false
          }


          function myfunction()
          {
          alert("ok")
          }

          function change()
          {
          document.getEle mentById("bu"). value="changed"
          }
          </script>


          Comment

          • Dave

            #6
            Re: question about captureEvents

            Look at my post just above yours and you will see that in the first script,
            it's impossible to click at anything, included buttons and menus (with NN7).
            My question was: why does the second script not work?

            Dave


            "Dom Leonard" <doml.removethi s@senet.andthis .com.au> wrote in message
            news:Y7r1b.438$ Ca5.12064@nnrp1 .ozemail.com.au ...[color=blue]
            > Dave wrote:
            >[color=green]
            > > Thanks again, it works with NN 7.
            > > But i still can click on the menu and other buttons of the browser. Is[/color][/color]
            it[color=blue][color=green]
            > > not possible to make this impossible?
            > >
            > > Dave
            > >
            > >[/color]
            > A thought is that capturing click events will not itself disable menus
            > and buttons driven by mousedown/mouseup instead of click events. If the
            > case, these would need separate listeneres/event capture.
            >
            > A quick google suggests that Internet Explorer 6 does not support event
            > capture as per DOM2 recommendations - meaning it does not support
            > addEventListene r registration - but does have its own attachEvent and
            > detachEvent methods. As far as I can determine IE does not support event
            > capture at all and would need modifications to event handlers at the
            > HTML tag or DOM node object level to get around the limitation.
            >
            > Cheers,
            > Dom
            >[/color]


            Comment

            • Dave

              #7
              Re: question about captureEvents

              Thanks for your explanation


              Comment

              Working...