[SOLVED] Cloaking Email Addresses

Ask for help or provide support to other members.
NorfolkGreg
Posts: 88
Joined: Wed Sep 01, 2021 7:50 am

[SOLVED] Cloaking Email Addresses

Post by NorfolkGreg »

It's been my practice over a number of years to use this snippet of JavaScript to cloak email address links on the web sites I produce, using this code:

Code: Select all

<script type="text/javascript">
	<!-- Begin
		who = "user";
		where = "mydomain.com";
		document.write('<a href=\"mailto:' + who + '@' + where + '\">');
		document.write('Email Me' + '<\/a>');
	// End -->
</script>
All was going well until I installed Summernote!

Now every time I edit the page I get multiple copies of the email link with the additional ones as standard mail link code

Code: Select all

<a href="mailto:user@mydomain.com">Email Me</a>
Is there a way to escape the Javascript so Summernote does not both leave the code on the page and produce its rendering of it. Editing the code direct through Summernote does not do it!
Last edited by NorfolkGreg on Fri Feb 04, 2022 8:45 pm, edited 3 times in total.
NorfolkGreg
Posts: 88
Joined: Wed Sep 01, 2021 7:50 am

Re: Cloaking Email Addresses

Post by NorfolkGreg »

Still more tragic things happen when I use this code in my footer:

Code: Select all

<p>&copy; 2008
	<script>
	new Date().getFullYear()>2008&&document.
	write("-"+new Date().getFullYear());
	</script>
	Organisation Name
</p>
to generate a line: "© 2008 -2021 Organisation Name"

The entire page disappears leaving me with just

-2021

on the screen!
OneManLaptop
Posts: 68
Joined: Tue Mar 16, 2021 3:29 pm

Re: Cloaking Email Addresses

Post by OneManLaptop »

Yeah, had a bizarre thing a few days ago. Edited the source of one site online and all the prices in my food menu vanished. The CMS definitely needs some TLC.
NorfolkGreg
Posts: 88
Joined: Wed Sep 01, 2021 7:50 am

Re: Cloaking Email Addresses

Post by NorfolkGreg »

Normally, I say it was probably a minor mis-keying that did that, but having looked at your Irish Pub site I know you have the skills to avoid any obvious mistypings. More likely you're right and it was a bug in Summernote.

I confess I hate what the Summernote editor does to one's carefully crafted and neatly indented code, but that's pretty standard for WYSIWYG code editors and, I guess, has to be tolerated, so one's users don't have to be intimidated into learning how to wrap content in a few simple HTML tags. I haven't checked but I strongly suspect that if I removed Summernote I could retain my JavaScript and keep email addresses cloaked.
OneManLaptop
Posts: 68
Joined: Tue Mar 16, 2021 3:29 pm

Re: Cloaking Email Addresses

Post by OneManLaptop »

NorfolkGreg wrote: Thu Nov 04, 2021 10:18 am Normally, I say it was probably a minor mis-keying that did that, but having looked at your Irish Pub site I know you have the skills to avoid any obvious mistypings. More likely you're right and it was a bug in Summernote.

I confess I hate what the Summernote editor does to one's carefully crafted and neatly indented code, but that's pretty standard for WYSIWYG code editors and, I guess, has to be tolerated, so one's users don't have to be intimidated into learning how to wrap content in a few simple HTML tags. I haven't checked but I strongly suspect that if I removed Summernote I could retain my JavaScript and keep email addresses cloaked.
Well that's very kind of you to say so. :)

A lot of Wonder CMS's development is tied up in Summernote, which makes things tricky for Wiz and co. I edited the site the other day using it and it all worked like a dream, but I won't be poking around in the source code without making a full backup!

My main concern right now is the image handling, every other week I have to run behind a client and edit the images they upload, because there's no resizing / resaving happening, so clients are uploading huge images to their site and obviously it kills performance.

I'm also changing my mind about having the save be automatic. I had a client do half an edit on their site, delete a load of things and then he was called away, but of course all his edits up to that point had been saved and were active on the live site so it was a huge mess and I had to quickly upload an old version, so I think that will need changing to force the user to explicitly save their updates. Be handy if they could store their edits in a temp file so they get the best of both worlds.

Only so many hours in the day, I wish I knew more about PHP / JSON so I could help them out.
NorfolkGreg
Posts: 88
Joined: Wed Sep 01, 2021 7:50 am

Re: Cloaking Email Addresses

Post by NorfolkGreg »

To avoid topic drift I've opening two new topics Image Handling and Auto Save Issues.
NorfolkGreg
Posts: 88
Joined: Wed Sep 01, 2021 7:50 am

Re: Cloaking Email Addresses

Post by NorfolkGreg »

I think this topic got marked [SOLVED] in error. My fault! We seem to have spawned a couple of additional issues.

I still wonder if there's a way to stop Summernote processing my JavaScript code to cloak email addresses. And here I must remind others my own understanding of JavaScript is extremely limited, so I need very basic instructions.

For example, could I simply include in my theme calls to external JavaScript files to generate the email addresses. Would having them outside the database stop Summernote processing them?
NorfolkGreg
Posts: 88
Joined: Wed Sep 01, 2021 7:50 am

Re: Cloaking Email Addresses

Post by NorfolkGreg »

I now realise that it's not Summernote that process the JavaScript. I have removed it from my site and I still find that the uncloaked email address appears in the code after the page is saved. :-(

Has anyone a suggestion on how to include email links in WCMS?
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: Cloaking Email Addresses

Post by wiz »

I don't think this is easily solvable, as document.write will always write the additional content each time you edit it. There's currently no way to disable JS parsing without probably breaking some WonderCMS websites that utilize it in some way.

You can also do some tricks with CSS: https://www.labnol.org/internet/hide-em ... ges/28364/
Or manually input the script somewhere in your theme.php to display it anywhere you want.
NorfolkGreg
Posts: 88
Joined: Wed Sep 01, 2021 7:50 am

Re: Cloaking Email Addresses

Post by NorfolkGreg »

Thanks for the thoughts and the link.!
I hadn't encountered the CSS hiding technique previously. I'll investigate that further.
I had wondered whether one could avoid the JS parsing by including the JavaScript in an external PHP include file, but that's probably naive and demonstrates how little I know about both JavaScript and PHP!
Post Reply