JavaScript onclick

From Market Ruler Help
Jump to: navigation, search

In a web page's HTML, a web developer can use JavaScript to trigger client-side code to track when a link is clicked.

The <a> HTML tag appears like so:

<a href="url">Click here to sign up</a>

The onclick attribute can be added to the <a> tag, and the value contains the JavaScript to run when the user:

  • Selects the link using the keyboard and then hits the Enter key, or
  • Clicks the link with their mouse, or
  • Taps the link with their finger on a Touch-based Device

To add the onclick method:

<a href="url" onclick="return __CR.link(this, '8')">Click here to sign up</a>

The onclick attribute should return a value which tells the browser whether to actually load the link or not. If the JavaScript function returns true, then the link will be followed, if it returns false, the link will not be followed.

This allows a program to, for example, put up a warning before following a link.

For more information