...

View Full Version : Hide Email Address In img src



dude9er
02-20-2007, 12:29 AM
I have an email address list that is dynamically genereated from an SQL Database. I want to write the address into a MAILTO: image using javascript, but can't figure out how to incorporate my ASP into the code.

I am using the JS here http://javascript.internet.com/page-details/spambot-countermeasure.html

Here is my code but it doesn't work:



'receive value from DB
<%= oRs.Fields("email") %>

'=========================

<script language="JavaScript"><!--

// hide script
<% Dim email as String
email= oRs.Fields("email")
if(email.IndexOf("@")>0){
%>
var sb_domain = "<%=email.Substring(email.IndexOf("@") + 1)%>";
var sb_user = "<%=email.Substring(0, (email.IndexOf("@") + 1))%>";
var sb_recipient = sb_user + sb_domain;
var sb_url = "mailto:" + sb_recipient;
document.write('<a href="'+sb_url+'"><img src="http://somesite.com/email1.jpg" border="0"/> </a>');
<%}%>
// --></script>



can someone help me write this, I getting loads of Microsoft VBScript errors. OR does anyone have a script that already functions?

Thanks!!!!

miranda
02-20-2007, 11:44 PM
Is this classic asp using VBScript as your server-side language?

If yes then you do not have either of these ( .Substring .IndexOf) available

IF you are using ASP.NET then you do have them

In classic asp use something similar to this


if(inStr(1,email,"@")>0)
%>
var sb_domain = "<%=Right(email,Len(email) - inStr(1,email,"@"))%>";
var sb_user = "<%=Left(email,Len(email) - inStr(1,email,"@")+ 1)%>";
var sb_recipient = sb_user + sb_domain;
var sb_url = "mailto:" + sb_recipient;
document.write('<a href="'+sb_url+'"><img src="http://somesite.com/email1.jpg" border="0"/> </a>');
// --></script>



Also VBScript does not use curly braces

degsy
02-21-2007, 02:39 PM
Is this classic asp using VBScript as your server-side language?

If yes then you do not have either of these ( .Substring .IndexOf) available
The script is a client side Javascript.



I am using the JS here http://javascript.internet.com/page-...ermeasure.html

Here is my code but it doesn't work:
You are getting mixed up between client-side javascript and ouputted server-side code.

Here is an example of what you wanted


<%While Not rs.EOF%>
<script language="JavaScript">
<!--// hide script

email = '<%=rs("fieldName")%>';
if(email.indexOf("@")>0){
var sb_domain = email.substring(email.indexOf("@") + 1);
var sb_user = email.substring(0, (email.indexOf("@") + 1));
var sb_recipient = sb_user + sb_domain;
var sb_url = "mailto:" + sb_recipient;
document.write('<a href="'+sb_url+'"><img src="http://somesite.com/email1.jpg" border="0"/> </a>');
}
// -->
</script>
<%
rs.MoveNext
Wend
%>



imo you are going about this the wrong way. If javascript is disabled then your script will not work.

You should setup a server-side form processing script to process emails.

dude9er
02-21-2007, 06:14 PM
THANKs for everyone's feedback.

degsy, your code works great, needed some minor adjustments, but is working!!

miranda
02-21-2007, 11:14 PM
The script is a client side Javascript.





Degsy relook at what he has for code. He had serverside and client side script mixed together. If you look at what his 1st post showed inside the asp delimiters then you will see that. because ASP can be done in JScript on the server is the reason why i asked that. He was definately mixing up the server and client side code

In particular this was not VBScript even though it was in delimiters



<% Dim email as String 'only variable type availabe in VBScript is variant
email= oRs.Fields("email")
if(email.IndexOf("@")>0){
%>

var sb_domain = "<%=email.Substring(email.IndexOf("@") + 1)%>";
var sb_user = "<%=email.Substring(0, (email.IndexOf("@") + 1))%>";

<%} %>

degsy
02-28-2007, 03:02 PM
I just meant that the script trying to be incorporated was a client-side javascript. You can see from the link posted.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum