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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft IIS Web Server

From novice to tech pro — start learning today.