简体   繁体   中英

How to Replace text with an image on javascript email link

I have an email link that uses javascript to protect the email address but I want to replace the link text with an image. How would I do this?

This is an example what I have on my website with the words "email me" as the clickable email link which I would like to replace with an image instead:

<script>mail2("name","fake-email",1,"?subject=Referral from website" "Email Me")</script>

And this is the code from the js file:

// Email.js version 5
var tld_ = new Array()
tld_[0] = "com";
tld_[1] = "com.au";
tld_[2] = "net";
tld_[3] = "ws";
tld_[4] = "info";
tld_[10] = "co.uk";
tld_[11] = "org.uk";
tld_[12] = "gov.uk";
tld_[13] = "ac.uk";
var topDom_ = 13;
var m_ = "mailto:";
var a_ = "@";
var d_ = ".";

function mail(name, dom, tl, params)
{
    var s = e(name,dom,tl);
    document.write('<a href="'+m_+s+params+'">'+s+'</a>');
}
function mail2(name, dom, tl, params, display)
{
    document.write('<a href="'+m_+e(name,dom,tl)+params+'">'+display+'</a>');
}
function e(name, dom, tl)
{
    var s = name+a_;
    if (tl!=-2)
    {
        s+= dom;
        if (tl>=0)
            s+= d_+tld_[tl];
    }
    else
        s+= swapper(dom);
    return s;
}
function swapper(d)
{
    var s = "";
    for (var i=0; i<d.length; i+=2)
        if (i+1==d.length)
            s+= d.charAt(i)
        else
            s+= d.charAt(i+1)+d.charAt(i);
    return s.replace(/\?/g,'.');
}

您要做的是将图像作为显示变量发送,如下所示:

<script>mail2("name","fake-email",1,"?subject=Referral from website",'<img src="src/to/image.jpg" />')</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM