Safari (Mac) issue

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

    Safari (Mac) issue

    The following code suppresses the 'enter' key, when run in I.E. 5.5 or
    later (Windows) but not when run in Safari (Mac)

    <body onkeypress="jav ascript:keysupp ress(event)" >

    function keysuppress(e)
    {
    if (e.type=="keypr ess" && e.keyCode=="13" )
    {
    event.returnVal ue=false
    }
    }

    What code can I use to suppress the 'enter' key when running an app in
    Safari?

    Thanks.

  • Lasse Reichstein Nielsen

    #2
    Re: Safari (Mac) issue

    Marcia Gulesian <mg@theworld.co m> writes:
    [color=blue]
    > The following code suppresses the 'enter' key, when run in I.E. 5.5 or
    > later (Windows) but not when run in Safari (Mac)[/color]

    .... or pretty much any non-IE browser.

    [color=blue]
    > <body onkeypress="jav ascript:keysupp ress(event)" >[/color]

    Just:
    <body onkeypress="key suppress(event) ">
    You almost never need to write "javascript :" in your pages.
    A better way would be:
    <body onkeypress="ret urn keysuppress(eve nt)">
    Returning false from the handler is the most consistent way of
    stopping an event.
    [color=blue]
    > function keysuppress(e)
    > {
    > if (e.type=="keypr ess" && e.keyCode=="13" )[/color]

    No need to test the event type when you are only called from an
    "onkeypress " intrinsic event handler - it will be a key press.

    The keyCode is a number, so it would be prettier to compare with the
    number 13 instead of the string "13". And marginally more efficient,
    if it mattered (it doesn't).
    [color=blue]
    > {
    > event.returnVal ue=false[/color]

    Here you use "event" instead of the variable "e". IE makes the event
    available as the global variable "event", but not all other browsers
    do. The "returnValu e" property of the event is also an IE invention.

    To be consistent with the W3C DOM, you should call the method
    "preventDefault " on the event (but obviously, IE doesn't have one).

    For maximal consistency, you would write:

    if (e.preventDefau lt) {
    e.preventDefaul t();
    } else {
    e.returnValue = false;
    }

    Or, with the addition of the "return" in the handler text above,
    you could just return false:
    ---
    function keysuppress(e) {
    return (e.keyCode != 13);
    }
    ---
    [color=blue]
    > What code can I use to suppress the 'enter' key when running an app in
    > Safari?[/color]

    I don't have access to Safari, but I'll be surpriced if this doesn't work.
    /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

    • Marcia Gulesian

      #3
      Re: Safari (Mac) issue

      Thank you Lasse.

      Lasse Reichstein Nielsen wrote:
      [color=blue]
      > Marcia Gulesian <mg@theworld.co m> writes:
      >[color=green]
      > > The following code suppresses the 'enter' key, when run in I.E. 5.5 or
      > > later (Windows) but not when run in Safari (Mac)[/color]
      >
      > ... or pretty much any non-IE browser.
      >[color=green]
      > > <body onkeypress="jav ascript:keysupp ress(event)" >[/color]
      >
      > Just:
      > <body onkeypress="key suppress(event) ">
      > You almost never need to write "javascript :" in your pages.
      > A better way would be:
      > <body onkeypress="ret urn keysuppress(eve nt)">
      > Returning false from the handler is the most consistent way of
      > stopping an event.
      >[color=green]
      > > function keysuppress(e)
      > > {
      > > if (e.type=="keypr ess" && e.keyCode=="13" )[/color]
      >
      > No need to test the event type when you are only called from an
      > "onkeypress " intrinsic event handler - it will be a key press.
      >
      > The keyCode is a number, so it would be prettier to compare with the
      > number 13 instead of the string "13". And marginally more efficient,
      > if it mattered (it doesn't).
      >[color=green]
      > > {
      > > event.returnVal ue=false[/color]
      >
      > Here you use "event" instead of the variable "e". IE makes the event
      > available as the global variable "event", but not all other browsers
      > do. The "returnValu e" property of the event is also an IE invention.
      >
      > To be consistent with the W3C DOM, you should call the method
      > "preventDefault " on the event (but obviously, IE doesn't have one).
      >
      > For maximal consistency, you would write:
      >
      > if (e.preventDefau lt) {
      > e.preventDefaul t();
      > } else {
      > e.returnValue = false;
      > }
      >
      > Or, with the addition of the "return" in the handler text above,
      > you could just return false:
      > ---
      > function keysuppress(e) {
      > return (e.keyCode != 13);
      > }
      > ---
      >[color=green]
      > > What code can I use to suppress the 'enter' key when running an app in
      > > Safari?[/color]
      >
      > I don't have access to Safari, but I'll be surpriced if this doesn't work.
      > /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.'[/color]

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Safari (Mac) issue

        Lasse Reichstein Nielsen wrote:[color=blue]
        > Marcia Gulesian <mg@theworld.co m> writes:[color=green]
        >> What code can I use to suppress the 'enter' key when running an app in
        >> Safari?[/color]
        >
        > I don't have access to Safari, but I'll be surpriced if this doesn't work.[/color]
        ^^^^^^^^^
        Sorry for the public "spelling flame" but since you do not seem to read
        your e-mails: It is _surprised_ and _surprise_. Seems to be a common
        mistake among European students that to not have English as native
        language, especially in Scandinavian countries (from what Google tells me).


        HTH

        \V/ PointedEars

        Comment

        Working...