Hide email address with JavaScript

User 2812921 Photo


Registered User
8 posts

Hello

Can someone please help me with this JavaScript?

The link-color does effect other links too.

I have little or no knowledge of programming. After a lot of searching and experimenting, this is how far I've come. Some parts of this script are confusing, and I would appreciate it very much if anyone could help me out.

This is the script that I've tried to put together. The uploaded file is a test-page that shows the script in action.
<span id="myemail"><script language="JavaScript" type="text/JavaScript">
emName = 'post'
emDomain = 'example.com'
emLink = 'Send An Email'

var em = (emName + String.fromCharCode(32 * 2) + emDomain)
document.write('<a href="mailto:' + em + '?subject=Hello there! :-)">' + emLink + '<\/a>')

var emLink = document.getElementById("myemail");
emLink.style.fontFamily = 'calibri';
emLink.style.fontSize = '25px';
emLink.style.fontWeight = '700';
emLink.style.lineHeight = '1,4';
emLink.style.textDecoration = 'underline';
colourLink("#e34c19");

function colourLink(hex) {
var link = document.getElementsByTagName("a");
for (var i=0; i<link.length; i++) {
if (link[i].href) {
link[i].style.color = hex;
}
}
}
</script></span>


Kjersti

Attachments:
User 187934 Photo


Senior Advisor
18,749 posts

Hi Mrs B,
Can you share a link to your page so we can see it live?
Also explain exactly what your looking for.:)
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

Here's my S-Drive site with
examples of what can be accomplished in VSD.
https://progrower.coffeecup.com/
Here's my CoffeeCup SCCP Shop with examples of what can be done.
https://progrower.coffeecup.com/shop/
This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 271657 Photo


Administrator
3,816 posts

http://hivelogic.com/enkoder/
Type in your info, click submit and get the code snippet to put on your site. ;)

You can also use the second option to include styling.
I love deadlines. I like the whooshing sound they make as they fly by. (Douglas Adams)
https://www.callendales.com
User 2812921 Photo


Registered User
8 posts

Eric Rohloff wrote:
Hi Mrs B,
Can you share a link to your page so we can see it live?
Also explain exactly what your looking for.:)


:lol: Hello Eric.
I can ensure you it was well explained - if you'd been a Norwegian that is, and inside my head. :) So I'll try again.
First of all, thank you.

When clicking the email-link, the script is working as expected. My problem is the color. I've styled the email-link with a color. However, the orange (test-) color don't apply to the email-link only, but to other links on the same page too. The strange thing is that this orange color only applies to links that are placed before the script, not after.

I want the script to make only my email link orange.

I hope this explanis what I mean. :)

Here is a link to a testpage I made.
URL DELETED

Kjersti
User 2812921 Photo


Registered User
8 posts

paintbrush wrote:
http://hivelogic.com/enkoder/
Type in your info, click submit and get the code snippet to put on your site. ;)

You can also use the second option to include styling.


Hello Paintbrush. :)

Thank you very much for the nice link. I will try it out. :)

Kjersti
User 2812921 Photo


Registered User
8 posts

paintbrush wrote:
http://hivelogic.com/enkoder/
Type in your info, click submit and get the code snippet to put on your site. ;)

You can also use the second option to include styling.


Thank you Paintbrush! A super-useful suggestion, and it works really grate! :)
User 271657 Photo


Administrator
3,816 posts

You're welcome :)
Happy to hear it worked for you.
I love deadlines. I like the whooshing sound they make as they fly by. (Douglas Adams)
https://www.callendales.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.