Suppress page juming to start

Discussion in 'Javascript' started by Emil Horowitz, Jul 3, 2007.

  1. Hi,

    if I wish to just execute JavaScript by clicking on a link, I do not have an
    alternativ to entering "#" as the URL. But this makes a scrolled page jump
    to its start. As far as I remember there is a command to prevent this and
    keep the page where it is, but I cannot remember what it is. Any help?

    Thank you,
    Emil
     
    Emil Horowitz, Jul 3, 2007
    #1
    1. Advertising

  2. Emil Horowitz

    Matt Kruse Guest

    On Jul 3, 12:36 pm, "Emil Horowitz" <> wrote:
    > if I wish to just execute JavaScript by clicking on a link, I do not have an
    > alternativ to entering "#" as the URL. But this makes a scrolled page jump
    > to its start. As far as I remember there is a command to prevent this and
    > keep the page where it is, but I cannot remember what it is. Any help?


    http://www.javascripttoolbox.com/bestpractices/#onclick

    Matt Kruse
     
    Matt Kruse, Jul 3, 2007
    #2
    1. Advertising

  3. Emil Horowitz

    ASM Guest

    Emil Horowitz a écrit :
    > Hi,
    >
    > if I wish to just execute JavaScript by clicking on a link, I do not have an
    > alternativ to entering "#" as the URL. But this makes a scrolled page jump
    > to its start. As far as I remember there is a command to prevent this and
    > keep the page where it is, but I cannot remember what it is. Any help?


    Ugly way :
    <a href="javascript:dothat();" blah
    <a href="javascript:void();" onclick="dothat();" blah

    OK :
    <a href="#" onclick="dothat(); return false;" blah

    Good :
    <a href="page_error.htm" onclick="dothat(); return false;" blah

    Better :
    <a href="page_error.htm" onclick="return dothat();" blah
    Here the function 'dothat()' has to return 'false'
    example :
    function dothat() {
    alert('Hello');
    return false;
    }

    --
    Stephane Moriaux et son (moins) vieux Mac
     
    ASM, Jul 3, 2007
    #3
  4. On Jul 3, 1:27 pm, ASM <>
    wrote:
    > Ugly way :
    > <a href="javascript:dothat();" blah
    > <a href="javascript:void();" onclick="dothat();" blah
    >
    > OK :
    > <a href="#" onclick="dothat(); return false;" blah
    >
    > Good :
    > <a href="page_error.htm" onclick="dothat(); return false;" blah
    >
    > Better :
    > <a href="page_error.htm" onclick="return dothat();" blah
    > Here the function 'dothat()' has to return 'false'
    > example :
    > function dothat() {
    > alert('Hello');
    > return false;
    > }



    <button onclick="dothat()">Best</button>
     
    scripts.contact, Jul 4, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. peshrad
    Replies:
    3
    Views:
    1,546
    David Freeman
    Nov 8, 2004
  2. Jon Davis
    Replies:
    0
    Views:
    894
    Jon Davis
    Nov 14, 2006
  3. Replies:
    1
    Views:
    398
    =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?=
    Aug 22, 2007
  4. Suppress ServerValidate on Page?

    , Oct 23, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    124
  5. Suppress ServerValidate on Page?

    , Oct 30, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    106
Loading...

Share This Page