Event object

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

    Event object

    <html>

    I pulled the following code off the internet. The idea is to intercept
    various user screen events. IOn this case it would just return the x y
    location of the cursor when the mouse is clicked in an alert. It doesn't run
    for me - I get "Event is undefined" error message. What's up?

    <script language="JavaS cript">
    window.captureE vents(Event.CLI CK);
    window.onclick= displayCoords;
    function displayCoords(e ) {
    alert("x: " + e.pageX + " y: " + e.pageY);
    }
    </script>



  • Simon Wigzell

    #2
    Re: Event object

    snip

    I see now that this example only works in navigator. Does anyone know of a
    more generalized function that will account for all browsers? (By "all" I
    mean IE and Netscape 5 or better and those that follow their protocols, I
    don't care if it doesn't work for someone using something totally obscure or
    old and out of date, I'll have a special message saying "bite me" for them.)


    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Event object

      "Simon Wigzell" <simonwigzell@s haw.ca> writes:
      [color=blue]
      > Does anyone know of a more generalized function that will account
      > for all browsers? (By "all" I mean IE and Netscape 5 or better and
      > those that follow their protocols, I don't care if it doesn't work
      > for someone using something totally obscure or old and out of date,
      > I'll have a special message saying "bite me" for them.)[/color]

      Since I use a browser that you seem to consider "obscure", I am *very*
      tempted to just say "bite me".

      Anyway, try this:
      ---
      <script type="text/javascript">
      if (typeof Event != "undefined" && window.captureE vents) {
      document.captur eEvents(Event.C LICK);
      }
      document.onclic k = function (evt) {
      evt = evt || window.event;
      if (typeof evt.pageX == "number") {
      var pageX = evt.pageX;
      var pageY = evt.pageY;
      } else {
      var root = document.compat Mode == "CSS1Compat " ?
      document.docume ntElement :
      document.body;
      pageX = evt.clientX + root.scrollLeft ;
      pageY = evt.clientY + root.scrollTop;
      }
      alert("x: " + pageX + " y: " + pageY);
      }
      </script>
      ---

      /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

      • Simon Wigzell

        #4
        Re: Event object

        snip

        Thanks, I thought I could use events to catch when the mouse was released
        from the scroll bar but that doesn't register. I'm still looking for a way
        to detect that event.


        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Event object

          Lasse Reichstein Nielsen wrote:
          [color=blue]
          > if (typeof Event != "undefined" && window.captureE vents) {[/color]
          ^^^^^^[color=blue]
          > document.captur eEvents(Event.C LICK);[/color]
          ^^^^^^^^[color=blue]
          > }[/color]

          Typo?


          PointedEars

          Comment

          Working...