Suppress page juming to start

E

Emil Horowitz

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
 
A

ASM

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;
}
 
S

scripts.contact

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>
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top