SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict artemis's Avatar
    Join Date
    Sep 2003
    Location
    London
    Posts
    295
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    javascript links with a little bit of class

    Hi,

    I am adding javascript email links to our website to stop spam bots from spamming our email addresses. I have used an external .js file with the following link on the page

    <script>safemail("email","sample.com")</script>

    How do I add a class ie class ="bodylink" to make this link fit in with the other links on the page? I cant use the deafult link style as this would mean rewriting code on the whole website to swap the styles around.

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    In your .js file look for the function safemail and replace the code with this:
    Code:
    function safemail(name, domain, cssClass) {
     var css = (typeof(cssClass)=="undefined") ? '' : cssClass;
     var str = '<a href="mailto:'
     + name + '@' + domain
     + '" class="'+css+'">'
     + name + '@' + domain + '<\/a>';
     document.writeln(str);
    }
    In your html file do the same thing as before but now you have an optional argument:

    HTML Code:
    //#1------------------------------
    
    <script type="text/javascript">
    safemail("you","you.com","bodylink");
    </script>
    
    /*
    outputs:
    <a href="mailto:you@you.com" class="bodylink">you@you.com</a>
    */
    
    //#2-------------------------------
    
    <script type="text/javascript">
    safemail("you","you.com");
    </script>
    
    /*
    outputs:
    <a href="mailto:you@you.com" class="">you@you.com</a>
    */
    -xDev

  3. #3
    SitePoint Addict artemis's Avatar
    Join Date
    Sep 2003
    Location
    London
    Posts
    295
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks xDev that works perrfectly


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •