Anchor Click Not Working in FireFox / Opera / Chrome

One issue that web developers trying to port a “designed for IE” application (to support more browsers) is the use of certain IE-specific method calls. One such is the use of .click on anchor tags. This method call will generate an error in browsers other than IE as it is not defined.

Here is one way to solve this issue, without changing the existing code. What we have to do is see if .click is defined and if not, define it with an alternative that works in our target browser.

By putting the above code in the head section of your page, we can ensure that .click is defined. You may need to change the this[“onclick”]() part based on your target browser.

Here is a sample piece of html for testing the above script. Clicking on the second link should navigate to target URL of the first link.

Leave a Reply

Your email address will not be published. Required fields are marked *