Skip to content

Instantly share code, notes, and snippets.

@jab416171
Created March 27, 2013 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jab416171/5255264 to your computer and use it in GitHub Desktop.
Save jab416171/5255264 to your computer and use it in GitHub Desktop.
Automatically detects if a user is logged into gmail, and if they are, will replace all the mailto: links on your webpage with links to the gmail compose window (automatically filling in the To field):
$('<img/>').hide()
.attr('src','https://mail.google.com/mail/photos/img/photos/public/AIbEiAIAAABDCKa_hYq24u2WUyILdmNhcmRfcGhvdG8qKDI1ODFkOGViM2I5ZjUwZmZlYjE3MzQ2YmQyMjAzMjFlZTU3NjEzOTYwAZwSCm_MMUDjh599IgoA2muEmEZD')
.load(function(){
$('a[href^="mailto:"]').each(function(){
var email = $(this).attr('href').replace(/^mailto:/,'');
$(this).attr('href','https://mail.google.com/mail/?view=cm&fs=1&tf=0&to='+escape(email));
});
})
.appendTo('body');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment