Google chrome click event not working

Hi guys
I am having a problem with the following line which included in an html file

<A href="#" onclick="index2(); return false;">Index</a>

it runs without a problem with Firefox and IE

With google chrome it reloads the current page and just ignores the click event...

This is a well known problem and is all over the web but I just wasn't able to find solution to my situation.

Who is Participating?
Robert SchuttSoftware EngineerCommented:
I would assume the page is not actually refreshed but the href="#" is 'executed' so the browser moves to the top of the page (that is what # actually means).

The only situation where I can reproduce this is when there is an error in index2().

So, a couple of things to do:
- check the code in function index2() for possible errors,
- add try/catch to that function to test for actual errors,
<script type='text/javascript'>
function index2() {
    alrt('x'); // this will cause an error because of the typo!
  catch (e)

Open in new window

- in general, if you do not want to jump to the start of the page, change the href (but this has negative implications for users with javascript disabled and screen readers):
<a href="javascript:void(0);" onclick="index2();">Index</a>

Open in new window

so actually it would be better if it is in any way possible to provide a real link as an alternative for when javascript is diabled, but this may not be applicable in your case.
<a href="alternative.htm" onclick="index2();">Index</a>

Open in new window

Hello Dory,

So, your link is supposed to execute the index2() javascript function.

The only reasonable explanation is that your javascript function contains code that is
unsupported by your Chrome browser
Robert SchuttSoftware EngineerCommented:
I think we're saying partly the same. We both failed to mention that an easy way to check for errors in your code is hit F12 in Chrome to show the Developer Tools and check the console and/or javascript sources. Note that this is less useful after adding try/catch(!)

<a id="here" href="#here" onclick="index2(); return false;">Index</a>

dory550Author Commented:
Sorry for the delay
Thanks for your help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.