Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Launching external protocols from anchors.
<p><a href="//" data-external="fb://profile/119703784116">Facebook</a>
<p><a href="//" data-external="foursquare://venues/4e4b3090fa7671a85ce77d0e">Foursquare</a>
<p><a href="//" data-external="twitter:/user?screen_name=oisfinc">Twitter</a>
<p><a href="//" data-external="yelp:/biz/orange-international-street-fair-orange">Yelp</a>
<p><a href="//" data-external="example:/foo">Example</a>
window.addEventListener('click', function (event) {
var target =;
// bubble up to the nearest anchor
while (target && target.nodeName !== 'A') {
target = target.parentNode;
// if an anchor exists with an external href, and the user would like to launch
if (target && target.hasAttribute('data-external') && confirm('Launch the external application?')) {
// cancel the href
// launch
location.href = target.getAttribute('data-external');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment