Grow your CSS skills. Land your dream job.

Get the mailto link without the mailto

  • # December 17, 2009 at 5:33 pm

    I’m working on a plugin for my company’s site. They have address on their site that go to outlook when clicked. I have my plugin concept I just need to grab the email from the link is clicked.

    how can i use javascript/jquery to strip the url from the link and ignore the "mailto:"

    # December 17, 2009 at 9:11 pm

    I’ve seen people use javascript to add links, so bots can’t take the email address.

    It’s not super practical, but it separates the name from the extension to prevent bots from reading it.

    Code:

    Email Joe

    # December 17, 2009 at 9:55 pm

    I’m not trying to protect the email address I want to grab it from the href:

    psdo code:

    Code:
    //give all mail links the class mailbox
    $(‘a[href^=mailto]’).addClass(‘mailbox’);

    $(‘.mailbox’).click(function()
    {
    //get the email link from the href

    //open new windows with the email link sent via an address (i have this part figured out)
    });

    What i’m trying to do now is get the email link:

    <a href="mailto: user@provider.com">email me</a>

    I want to pull out the "user@provider.com". I will never know what the email address is going to be so i cant search for a specific email either.

    Look like i need to get the enter href (mailto: user@provider.com) then remove the mailto: part. Once i have that I can send it to a php driven form using http://www.site.com/contact.php?email=user@provider.com.

    # December 18, 2009 at 10:24 am

    If your using jQuery then grab the attribute

    Code:
    $(‘.mailto’).click(function() {
    href = $(this).attr(‘href’);
    })
    # December 18, 2009 at 10:43 am

    I just got that part about 10min ago. Now i’m trying to to figure out how to strip the "mailto: " from it:

    Code:
    $(function()
    {
    $(‘a[href^=mailto]’).addClass(‘mailbox’);
    $(‘.mailbox’).click(function()
    {
    var url = $(this).attr(‘href’);

    alert(url);

    return false;
    });
    });

    this is my test to see when i get the url whittled down to just the email address. so far it shows "mailto: user@provider.com"

    # December 18, 2009 at 5:24 pm

    Try this.

    Code:
    $(function() {
    $(‘a[href^=mailto]’).addClass(‘mailbox’);
    $(‘.mailbox’).click(function()
    {
    var url = $(this).attr(‘href’);

    url = url.replace(/mailto: /, ”);

    alert(url);

    return false;
    });
    });

    # December 18, 2009 at 5:46 pm

    figured it out after hammering away. Thats basically how I did it. I used replace to locate the mailto: and replace it with ""

    # February 8, 2010 at 11:08 pm

    thats nice!! thanks a lot.. :mrgreen: resell rights

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".