3

I try to prevent page reload when user click a link, so I wrote :

<a href="javascript: return false">bla</a>

Or

<a href="#">bla</a>

Seriously I don't like to use # because when user click on the link, the url on the address bar is added the symbol #, it make the url look ugly. So I prefer to use javascript: return false but firebug show error : "return not in function", may I know how to fix the error?

zac1987
  • 2,721
  • 9
  • 45
  • 61

3 Answers3

6

See this discussion: Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

Do not use href="#". If it has to be, either use "javascript:;" or "javascript:void(0);"

Community
  • 1
  • 1
Alex Pakka
  • 9,466
  • 3
  • 45
  • 69
0

Try using this instead:

<a href="javascript:;">bla</a>

Hope that helps.

Oliver Spryn
  • 16,871
  • 33
  • 101
  • 195
0

Look at this (jsfiddle here):

<a href="http://www.google.com/" onclick="return false;">click me</a>

However, you should avoid using inline JavaScript. The JS in one place, separated from the code, has higher maintainability.

Tadeck
  • 132,510
  • 28
  • 152
  • 198