Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

ping — hyperlink auditing

The ping attribute on a and area elements lists URLs to notify when a hyperlink is followed. It does not change the href destination, and the browser may suppress notifications.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

ping="URL [URL ...]"

ping provides hyperlink auditing on a and area elements. href specifies the navigation destination, whereas ping identifies notification recipients. Without href, the element does not create a hyperlink.

Its value is a list of URLs separated by ASCII whitespace, not commas. Each token must be a valid, non-empty URL with an HTTP(S) scheme. Relative URLs are resolved against the document.

When the user follows the hyperlink, the browser may send each recipient a POST request with Content-Type: text/ping and body PING, independently of the navigation result. Response bodies are ignored.

This is an activity-tracking mechanism: the browser may suppress all or selected notifications according to user preferences. Do not treat ping as guaranteed proof of a visit or make application correctness depend on it.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="Content-Security-Policy" content="connect-src 'none'">
  <title>Hyperlink auditing targets</title>
</head>
<body>
  <a id="continue" href="#destination" ping="./audit-one ./audit-two">Continue</a>
  <p id="destination">Destination</p>
  <script>
    const link = document.getElementById('continue');
    for (const type of ['click', 'auxclick']) {
      link.addEventListener(type, event => event.preventDefault());
    }
    const targets = link.ping.match(/[^\t\n\f\r ]+/g) ?? [];
    console.log('Ping targets: ' + targets.join(', '));
    console.log('Link destination: ' + link.hash);
  </script>
</body>
</html>

Result

Ping targets: ./audit-one, ./audit-two
Link destination: #destination

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources