ping Attribute

By  on  

One of the attributes I somehow missed with the HTML5 revolution was the ping attribute;  Other attributes were more popular, download being one of them.  Hell, I just stumbled upon the ping attribute while reading an old forum post.  The ping attribute of an a element represents a list of URLs to POST to when the link is clicked.

A sample usage of the ping attribute would look as follows:

<a href="/checkout" ping="/tracking/going-to-cart">Checkout</a>

I tried writing the POST data to file but the PHP $_POST array was empty, so I can only assume no data is passed.  As for why you'd use the attribute...I don't know.  JavaScript tools provide tracking capabilities so I can only assume these POST pings can be coupled with session tracking to get more detailed information.

Have you used the ping attribute before?  If so please let me know what you used it for!

Recent Features

  • By
    Serving Fonts from CDN

    For maximum performance, we all know we must put our assets on CDN (another domain).  Along with those assets are custom web fonts.  Unfortunately custom web fonts via CDN (or any cross-domain font request) don't work in Firefox or Internet Explorer (correctly so, by spec) though...

  • By
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

Incredible Demos

  • By
    Full Width Textareas

    Working with textarea widths can be painful if you want the textarea to span 100% width.  Why painful?  Because if the textarea's containing element has padding, your "width:100%" textarea will likely stretch outside of the parent container -- a frustrating prospect to say the least.  Luckily...

  • By
    Create a CSS Flipping Animation

    CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...

Discussion

  1. In a similar fashion to navigator.sendBeacon, the “ping” attribute fulfills the request in the background, thus it’s not suspcentible to common document unloading problems when sending requests..

  2. Any sense of browser support?

  3. Drew

    I remember hearing about this many years ago (I think the last draft of specs to include it were in 2010, and it hasn’t been included since), but browser support was iffy. I think FF allows it only if the user modifies their about:config, there’s no real push for IE support, and Chrome/webkit supposedly support it but that’s not enough to recommend it’s use when it’s not on track to become a spec.

    It was meant to be used primary for analytics and tracking, for the reasons Adam mentions (the request wouldn’t get canceled by the navigation itself).

  4. Matt

    It is designed for advertisers. The idea is to have a banner ad that links to the advertiser while having a click tracker go to the ad supply company without having to ad 3rd party JS that who knows what it does.

    Since this is designed for advertisers, Google obviously has it working in Chrome, but Firefox doesn’t really care. Because of this, the ad industry just makes the click through url hit the ad supply site for tracking and then it redirects you to the actual ad url.

  5. Numa

    Just see that Google use it on results search links

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!