Catching window events

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

    #1

    Catching window events

    hi all,

    This is about javascript window events. I have a simple html file like
    this
    <html>
    <head>
    </head>
    <body onmousedown="al ert()">
    <form>
    <input type="text">
    </form>
    </body>
    </html>

    But alert is only popped whenever I click the mouse near by the input
    field. It is not catching the event for the entire browser window. Can
    anyone point out what is wrong in this html?

    Thanks,
    Vijay

  • Joakim Braun

    #2
    Re: Catching window events

    <vijay21@gmail. com> skrev i meddelandet
    news:1115286553 .113543.73190@z 14g2000cwz.goog legroups.com...[color=blue]
    > hi all,
    >
    > This is about javascript window events. I have a simple html file like
    > this
    > <html>
    > <head>
    > </head>
    > <body onmousedown="al ert()">
    > <form>
    > <input type="text">
    > </form>
    > </body>
    > </html>
    >
    > But alert is only popped whenever I click the mouse near by the input
    > field. It is not catching the event for the entire browser window. Can
    > anyone point out what is wrong in this html?[/color]

    The answer is probably that the body by default doesn't extend to fill the
    entire browser window.

    Try adding some CSS that makes height/width of body 100%.

    --
    Joakim Braun


    Comment

    • vijay21@gmail.com

      #3
      Re: Catching window events

      Hi Joakim,

      I tried adding body style="height:1 00%;width:100%" to the body tag.
      Now, it is always displaying scroll bars inside the explorer. It is
      also not truly encompassing the whole browser window. It's 0,0
      coordinates seem to be startting from the point text box appears. The
      thin margins on the top left are not capturing the event.

      Is there some way by which I can add the eventhandler to the window
      itself and not just body? I think I have seen such pages where they do
      such stuff.

      Thankyou for helping...

      Comment

      • Bonnett

        #4
        Re: Catching window events


        vija...@gmail.c om wrote:[color=blue]
        > Hi Joakim,
        >
        > I tried adding body style="height:1 00%;width:100%" to the body tag.
        > Now, it is always displaying scroll bars inside the explorer. It is
        > also not truly encompassing the whole browser window. It's 0,0
        > coordinates seem to be startting from the point text box appears. The
        > thin margins on the top left are not capturing the event.
        >
        > Is there some way by which I can add the eventhandler to the window
        > itself and not just body? I think I have seen such pages where they[/color]
        do[color=blue]
        > such stuff.
        >
        > Thankyou for helping...[/color]

        Try:

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
        <html lang="en-GB">
        <head>
        <title>Window Alert</title>
        <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
        <script type="text/javascript">
        window.onmoused own = function() { alert("This will get really
        irritating."); };
        </script>
        </head>
        <body>

        </body>
        </html>

        Comment

        • vijay21@gmail.com

          #5
          Re: Catching window events

          Hi Bonnett,

          This is running really well on Mozilla but I don't know why it is not
          doing anything on Internet Explorer. Looks like IE is completely
          ignoring this. Any guesses why so...

          Thankyou very much,

          Comment

          • Fred Oz

            #6
            Re: Catching window events

            vijay21@gmail.c om wrote:[color=blue]
            > hi all,
            >
            > This is about javascript window events. I have a simple html file like
            > this
            > <html>
            > <head>
            > </head>
            > <body onmousedown="al ert()">
            > <form>
            > <input type="text">
            > </form>
            > </body>
            > </html>
            >
            > But alert is only popped whenever I click the mouse near by the input
            > field. It is not catching the event for the entire browser window. Can
            > anyone point out what is wrong in this html?
            >
            > Thanks,
            > Vijay
            >[/color]

            <style type="text/css">
            body {border: 0; margin: 0; width: 100%; height: 100%;}
            </style>

            If IE persists with scrollbars, reduce width/height to 99%. IE 5.2
            on Mac doesn't show scrollbars at 100%.



            --
            Fred

            Comment

            • Bonnett

              #7
              Re: Catching window events

              After a quick google + test, it seems IE uses document.moused own rather
              than window.mousedow n, however I do not know what the browser
              limitations are on this, mozilla firefox 1.0.3 accepts
              document.moused own, but older version may not.

              Comment

              • vijay21@gmail.com

                #8
                Re: Catching window events

                Hi Bonnet and Fred,
                Many thanks for fishing this out. I have got what I wanted.
                Thanks,

                Comment

                • RobB

                  #9
                  Re: Catching window events

                  vija...@gmail.c om wrote:[color=blue]
                  > hi all,
                  >
                  > This is about javascript window events. I have a simple html file[/color]
                  like[color=blue]
                  > this
                  > <html>
                  > <head>
                  > </head>
                  > <body onmousedown="al ert()">
                  > <form>
                  > <input type="text">
                  > </form>
                  > </body>
                  > </html>
                  >
                  > But alert is only popped whenever I click the mouse near by the input
                  > field. It is not catching the event for the entire browser window.[/color]
                  Can[color=blue]
                  > anyone point out what is wrong in this html?
                  >
                  > Thanks,
                  > Vijay[/color]

                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                  "http://www.w3.org/TR/html4/str­ict.dtd">
                  <html>
                  <head>
                  <style type="text/css">
                  html { padding: 20px; cursor: help; }
                  body { margin:0; height:100%; }
                  input { cursor: help; }
                  </style>
                  <script type="text/javascript">
                  document.getEle mentsByTagName( 'html')[0].onmousedown =
                  function(e)
                  {
                  e = e || window.event;
                  tgt = e.srcElement || e.target;
                  alert(tgt.tagNa me);
                  }
                  </script>
                  </head>
                  <body>
                  <form>
                  <input type="text">
                  </form>
                  </body>
                  </html>


                  Join Earth's biggest chatroom — Mollyverse, a free 3D browser MMO. Chat with players worldwide, explore a chibi Central Park, and fly. No download.


                  btw moz/gecko requires arguments to alert(...)

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Catching window events

                    vijay21@gmail.c om wrote:
                    [color=blue]
                    > I tried adding body style="height:1 00%;width:100%" to the body tag.
                    > Now, it is always displaying scroll bars inside the explorer.[/color]

                    1. [X] You only know Internet Explorer. [psf 2.9]

                    <OT>

                    2. You have to format the element position:absolu te, too. Tests (with
                    ObjectInspector ) showed that the following stylesheet is suited for
                    the task:

                    body {
                    position:absolu te;
                    margin:0;
                    width:99%;
                    height:99%;
                    }

                    html>body {
                    width:auto;
                    height:auto;
                    left:0;
                    top:0;
                    right:0;
                    bottom:4px;
                    }

                    </OT>


                    PointedEars

                    Comment

                    Working...