I have a link (on a Font Awesome icon), that looks like this:
<a href="https://twitter.com/intent/tweet?text=Some text about this link&url=http://some.site.co/wow/greatamp;via=toby1kenobi">
<span class="fa fa-twitter-square"></span>
</a>
and I'm using the Javascript snippet under 'Limited Dependencies' on this page, this is just after the link. It's the only web intent on the page.
If I click the link the Twitter popup opens and the original page navigates to the same content displayed in the popup.
I can't figure out what I've done wrong - if I attach another event to the link and call preventDefault(), that stops the duplication, but I gather that shouldn't be necessary.
EDIT Here is Twitter's code:
(function() {
if (window.__twitterIntentHandler) return;
var intentRegex = /twitter\.com(\:\d{2,4})?\/intent\/(\w+)/,
windowOptions = 'scrollbars=yes,resizable=yes,toolbar=no,location=yes',
width = 550,
height = 420,
winHeight = screen.height,
winWidth = screen.width;
function handleIntent(e) {
e = e || window.event;
var target = e.target || e.srcElement,
m, left, top;
while (target && target.nodeName.toLowerCase() !== 'a') {
target = target.parentNode;
}
if (target && target.nodeName.toLowerCase() === 'a' && target.href) {
m = target.href.match(intentRegex);
if (m) {
left = Math.round((winWidth / 2) - (width / 2));
top = 0;
if (winHeight > height) {
top = Math.round((winHeight / 2) - (height / 2));
}
window.open(target.href, 'intent', windowOptions + ',width=' + width +
',height=' + height + ',left=' + left + ',top=' + top);
e.returnValue = false;
e.preventDefault && e.preventDefault();
}
}
}
if (document.addEventListener) {
document.addEventListener('click', handleIntent, false);
} else if (document.attachEvent) {
document.attachEvent('onclick', handleIntent);
}
window.__twitterIntentHandler = true;
}());
It binds to the click event of the document (rather than any anchors), I don't understand why it does not cancel the default navigation though. It seems to hit the "e.preventDefault && e.preventDefault();" line ok.