WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] JavaScript email link (4 posts)

  1. Jonathan Landrum
    Member
    Posted 9 years ago #

    Hello all,

    I ran across a way to use javascript to place an email link on a page, rather than an anchor. The reasoning behind this is that crapbots will have a tougher time at harvesting the email address this way. Here's the script:


    <script type='text/javascript'>var a = new

    Array(' "MAILTO:" in ASCII characters ',' first 7 characters of your address ',' second 7 characters of your address ',' et cetera... ');document.write("<a

    href='"+a[0]+a[1]+a[2]+a[3]"'>"+a[0]+a[1]+a[2]+a[3]"</a>");</script>
    <noscript><img src=" location of the image of your email address " title=" img title "></noscript>

    After Array(' enter your email address seven characters at a time between single quotes, no spaces, separated by a comma. Then, after href=' enter +a[0]+a[1]+a[2]... until you've entered all the groups required to fit your address. Do the same between the anchor tags for the name, or enter a set of words. The <noscript> tags are for people who've disabled javascript.

    Now, here's the question. How do I use javascript in WP? When I placed the code on my "contact" page it didn't show up. There was just a blank there. Any takers?

    ~Jonathan

  2. You should just be able to place it anywhere in your sidebar or footer and have it appear. I think something's wrong with your javascript, but I'm no js coder. What I would suggest, since you are going for a javascript email link, is that you go for a javascript encrypted email link: http://automaticlabs.com/products/enkoderform

  3. Jonathan Landrum
    Member
    Posted 9 years ago #

    Hey macmanx, no luck. I checked FF to make sure I have javascript enabled, and I do. I also added a <noscript> tag after the script Enkoder created and it still didn't work. I'm adding this script to a separate page I created in wp-admin called "Contact Me". Perhaps I should just have the Contact Me link go directly to my email address, insead of opening a new page. I'll try doing that and sticking it in the footer, like you suggested.

    ~Jonathan

  4. Jonathan Landrum
    Member
    Posted 9 years ago #

    Yeah, that did it. For some reason, it wouldn't let me put the script in the page. I checked the source of the page and the script was there, no problem. I'll bet, though, WP "cleaned" the script by adding breaks and paragraphs at every new line, or something like that :)
    Thanks for your help.

    ~Jonathan

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.