onclick - page should stay where it is in browser.

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

    onclick - page should stay where it is in browser.

    I'm using onclick in a link. I would like the page not to go back to the
    top when I click on the link.

    I'm using :

    <a onclick="popEdi tor()" href="#">Editor </a>

    This takes the page up top the top. If it's href="" then the results of the
    popEditor() function appear in the current page. What is the syntax? Thanks!
    I should know better by now but I finally got sick of my onclicks making the
    current page go to the top and now it's time to fix it.


  • Lasse Reichstein Nielsen

    #2
    Re: onclick - page should stay where it is in browser.

    "Simon Wigzell" <simonwigzell@s haw.ca> writes:
    [color=blue]
    > I'm using onclick in a link. I would like the page not to go back to the
    > top when I click on the link.[/color]
    [color=blue]
    > I'm using :
    >
    > <a onclick="popEdi tor()" href="#">Editor </a>
    >
    > This takes the page up top the top.[/color]

    In some browsers. In other browsers it takes it to the bottom. Both
    are reasonable behaviors when you link to an empty (or non-existant)
    fragment identifier.
    [color=blue]
    > If it's href="" then the results of the popEditor() function appear
    > in the current page.[/color]

    That sounds interesting. Are you sure you are not confuzing it with
    href="javascrip t:popEditor()" (which is bad style for several reasons,
    one of which is that the result becomes the new content of the page).
    [color=blue]
    > What is the syntax? Thanks![/color]

    First, why are you using an "a" element for something that is not a
    link? Your problem comes from using a link element, but not wanting
    the normal behavior of a link.

    What should the link do for people without javascript? Put that in the
    href.

    Then, to prevent the normal behavior of a link, you must return false
    from the onclick handler:

    <a href="nonJS.htm l" onclick="popEdi tor();return false;">Editor</a>
    [color=blue]
    > I should know better by now but I finally got sick of my onclicks making the
    > current page go to the top and now it's time to fix it.[/color]

    I suggest making it a button instead.

    /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

    • Simon Wigzell

      #3
      Re: onclick - page should stay where it is in browser.

      Thanks, the "return false;" is what I was looking for!

      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
      news:smoo9aqa.f sf@hotpop.com.. .[color=blue]
      > "Simon Wigzell" <simonwigzell@s haw.ca> writes:
      >[color=green]
      > > I'm using onclick in a link. I would like the page not to go back to[/color][/color]
      the[color=blue][color=green]
      > > top when I click on the link.[/color]
      >[color=green]
      > > I'm using :
      > >
      > > <a onclick="popEdi tor()" href="#">Editor </a>
      > >
      > > This takes the page up top the top.[/color]
      >
      > In some browsers. In other browsers it takes it to the bottom. Both
      > are reasonable behaviors when you link to an empty (or non-existant)
      > fragment identifier.
      >[color=green]
      > > If it's href="" then the results of the popEditor() function appear
      > > in the current page.[/color]
      >
      > That sounds interesting. Are you sure you are not confuzing it with
      > href="javascrip t:popEditor()" (which is bad style for several reasons,
      > one of which is that the result becomes the new content of the page).
      >[color=green]
      > > What is the syntax? Thanks![/color]
      >
      > First, why are you using an "a" element for something that is not a
      > link? Your problem comes from using a link element, but not wanting
      > the normal behavior of a link.
      >
      > What should the link do for people without javascript? Put that in the
      > href.
      >
      > Then, to prevent the normal behavior of a link, you must return false
      > from the onclick handler:
      >
      > <a href="nonJS.htm l" onclick="popEdi tor();return false;">Editor</a>
      >[color=green]
      > > I should know better by now but I finally got sick of my onclicks making[/color][/color]
      the[color=blue][color=green]
      > > current page go to the top and now it's time to fix it.[/color]
      >
      > I suggest making it a button instead.
      >
      > /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.'[/color]


      Comment

      Working...