Difference between revisions of "JavaScript onclick"
From Market Ruler Help
(Created page with '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: …') |
|||
Line 13: | Line 13: | ||
To add the '''onclick''' method: | To add the '''onclick''' method: | ||
− | <code><a href="''url''" onclick="return | + | <code><a href="''url''" onclick="return __CR.link(this, '8')">Click here to sign up</a></code> |
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. | 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. |
Latest revision as of 15:50, 26 February 2016
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.