Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE7 and the spam free mailto problem

Status
Not open for further replies.

raduchelariu

Technical User
Mar 9, 2009
8
RO
Hi everyone,

This is my script:

function MailSimple() { javascript:window.location="mai"+"lto:"+"contact"+"@"+"web"+"site"+"."+ "com"; }

And my HTML:
<a href="#" onclick="MailSimple();return false;"><img src="mailto.jpg" /></a>

Now this is my problem:
In every other browser on the planet everything is going smooth. You click and your e-mail client neatly opens up.
But in IE7 (particularly Vista + IE7) whenever one clicks the link it not only opens the e-mail client but also another, blank, page.

Really hope you guys can help me out here.
 
I'd either use a contact form or use non-JS for this.

With the latter, you might even go so far as encoding the whole thing:


(select the "character entities" option).

That would help avoid spam, but make your link work for those without JS as well.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi

Dan said:
That would help avoid spam
I would not be so sure. That is an ancient trick which never offered 100% protection because with most of the HTML libraries is only one function call to decode it.
Dan said:
make your link work for those without JS as well.
Yes, but I am not sure it will work in all browsers, while that generates invalid HTML : all semicolons ( ; ) are missing.

Feherke.
 
Thanks for your quick replies.
While the HTML Obfuscation method is attractive in many ways, moreso than the Character Encoding one they both have their fault, as pointed out by feherke. On my part I dislike them both because they are very non-semantica and while I will admit my method isn't exactly booletproof (you still need JS turned on) it has, at least to me, the advantage of being semantic and easily maintainable as well as self sufficient (does not require the use of an external application).

I have hope for this method and I suppose that's why I really want this one to work.

Someone suggested to me that window.location might be the culprit but that was quickly dismissed because document.location yielded the same problem in IE7 and the same normal functionality in every other browser.

I guess the search is still on.
 
Hi

Why is the [tt]javascript:[/tt] pseudo-protocol mentioned in the [tt]function[/tt] declaration ? Remove it.
Code:
function MailSimple()
{
  window.location="mai"+"lto:"+"contact"+"@"+"web"+"site"+"."+ "com";
}

Feherke.
 
Thanks for the idea but it resolved nothing. The same problem occurs.

Just for the kick of it, has anyone been able to duplicate the problem? It seems this does not happen to every Vista+IE7 combo. I was unable to determine the factor that triggers the faulty behaviour so I it's a matter of blind trial I suppose.
 
Hi

I can not reproduce it because I have none of those software. I only suggested to correct the syntax error.

Just a try. This is the variant I saw more frequently :
JavaScript:
function MailSimple([red]what[/red])
{
  [red]what.href[/red]="mai"+"lto:"+"contact"+"@"+"web"+"site"+"."+ "com";
}
HTML:
<a href="#" onclick="MailSimple([red]this[/red])"><img src="mailto.jpg" /></a>
( Note the absence of the [tt]return[/tt] after the call. )

Feherke.
 
Ok, I tried your fix, feherke, but, unfortunately, it did not help as much as I hoped. IE7 indeed did not open a new window. Instead it opened a new tab. So it's basically the same problem, with just this slight diference.
 
how about this method:

Code:
<html>
<head>
<script language="javascript">
function initMailTo() {
	document.getElementById("mailLnk").onclick = function() { window.location.href="mai"+"lto:"+"contact"+"@"+"web"+"site"+"."+ "com";return true; }
}
</script>
</head>
<body>
<a id="mailLnk" href="#" onClick="return false;"><img src="mailto.jpg" /></a> 
<script>
initMailTo();
</script>
</body>

You can do the init right after the <a> tag, or put it in your body tag as an OnLoad event.

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Okay, I wasn't really sure what that was going to solve but I thought I'd give it a try. Sorry, but no dice. Did not work.

I'm starting to be more and more convinced that this is in fact an IE7/Vista security issue. I can almost imagine the guys at Microsoft: "Hey, guys, we still have security issues with (IE)7. Should we fix them? - Neah, let's just make it open up another window. No one will mind.".....sigh
 
Hi

raduchelariu said:
IE7 indeed did not open a new window. Instead it opened a new tab.
Hmm... I can imagine there is kind of (mis)configuration in your browser. Does plain HTML [tt]a[/tt] tags ( without JavaScript ) with [tt]mailto:[/tt] work correctly ? Maybe something strange is associated to handle that protocol.

Feherke.
 
Nope. Regular mailtos work just as they should. Click -> Open mail client and nothing else.
 
Hmmm...that's a good thought. I have a lighbox clone loaded. I removed it but the strange behaviour just won't quit. This is one of those times when I hate IE7 more than IE6. At least good ol' 6 has well referenced bugs.

Well, thanks for your help guys. I'm just about ready to give this one up.
 
I'm just about ready to give this one up.

Given you have no other solution that works with JS, and given you know regular mailto links work, why not go with either of my suggestions? They would both work.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Check it out:



I'm running Vista and tested it with
IE 7
FF 3
Safari 3

Works like a charm on all three browsers.


Code:
<html>
<head>
<script language="javascript">
function initMailTo() {
    document.getElementById("mailLnk").onclick = function() { window.location.href="mai"+"lto:"+"someone"+"@"+"some"+"where"+"."+ "com";return true; }
}
</script>
</head>
<body>
<a id="mailLnk" href="#" onClick="return false;">Click To Email</a> 
<script>
initMailTo();
</script>
</body>

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Ok....that's weird. I checked your example out and I don't get the issue anymore. It could very well be something at my end. I'm going to have to do some extended cross-platform testing but all'n'all this does seem to be the right way to go.

I appreciate everyone's help very much. Thanks a lot guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top