onclick - page should stay where it is in browser.

S

Simon Wigzell

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="popEditor()" 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.
 
L

Lasse Reichstein Nielsen

Simon Wigzell said:
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="popEditor()" href="#">Editor</a>

This takes the page up top the top.

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.
If it's href="" then the results of the popEditor() function appear
in the current page.

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

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:

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.

I suggest making it a button instead.

/L
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,077
Messages
2,570,569
Members
47,205
Latest member
KelleM857

Latest Threads

Top