webForumDet fria alternativet

Skapa mailto-länk vid epostadresser.

ASP

2 svar · 216 visningar · startad av Oputres

Medlem sedan feb. 2004333 inlägg
Frågan#1

Allå! Jag har då nedanstående funktion som skapar klickbara länkar av webbadresser. Kan man integrera till i samma funktion att den skapar mailto-länkar om man skriver in en epostadress?

Function Visa(s)
dim objRE, m, o
On error resume next
Set objRE = new RegExp 
objRE.IgnoreCase = True : objRE.Global = True 
objRE.Pattern = "(http:\/\/|www\.)(\w|\&|\:|\;|\.|\/|\?|\~|\=|-)+"
Set m = objRE.Execute(s) 
For Each o In m 
If Right(o.Value, 1)="." Or Right(o.Value, 1)="!" Or Right(o.Value, 1)="?" Or Right(o.Value, 1)="," Then 
If Left(o.Value, 3) = "www" Then s = Replace(s, o.Value, "<A HREF=""http://" & Left(o.Value, Len(o.Value)-1) & """ target=""_blank"">" & Left(o.Value, Len(o.Value)-1) & "</A>" & Right(o.Value, 1)) Else s = Replace(s, o.Value, "<A HREF=""" & Left(o.Value, Len(o.Value)-1) & """>" & Left(o.Value, Len(o.Value)-1) & "</A>" & Right(o.Value, 1)) 
Else 
If Left(o.Value, 3) = "www" Then s = Replace(s, o.Value, "<A HREF=""http://" & o.Value & """ target=""_blank"">" & o.Value & "</A>") Else s = Replace(s, o.Value, "<A HREF=""" & o.Value & """ target=""_blank"">" & o.Value & "</A>") 
End If 
Next 
Set objRE = Nothing
Medlem sedan dec. 20025 483 inlägg
#2

Exempel:

Function Visa(s)
dim objRE, m, o
On error resume next
Set objRE = new RegExp 
objRE.IgnoreCase = True : objRE.Global = True 
objRE.Pattern = "(http:\/\/|www\.)(\w|\&|\:|\;|\.|\/|\?|\~|\=|-)+"
Set m = objRE.Execute(s) 
For Each o In m 
If Right(o.Value, 1)="." Or Right(o.Value, 1)="!" Or Right(o.Value, 1)="?" Or Right(o.Value, 1)="," Then 
If Left(o.Value, 3) = "www" Then s = Replace(s, o.Value, "<A HREF=""http://" & Left(o.Value, Len(o.Value)-1) & """ target=""_blank"">" & Left(o.Value, Len(o.Value)-1) & "</A>" & Right(o.Value, 1)) Else s = Replace(s, o.Value, "<A HREF=""" & Left(o.Value, Len(o.Value)-1) & """>" & Left(o.Value, Len(o.Value)-1) & "</A>" & Right(o.Value, 1)) 
Else 
If Left(o.Value, 3) = "www" Then s = Replace(s, o.Value, "<A HREF=""http://" & o.Value & """ target=""_blank"">" & o.Value & "</A>") Else s = Replace(s, o.Value, "<A HREF=""" & o.Value & """ target=""_blank"">" & o.Value & "</A>") 
End If 
Next 

objRE.Pattern = "([^\s]+@([^\s]+\.)+\w{2,6})"
Visa = objRE.replace(s, "<a href=""mailto:$1"">$1</a>")
Set objRE = Nothing
end function
Medlem sedan feb. 2004333 inlägg
#3

Underbart!

250 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
122 ms — deklarationer (db)
0 ms — hämta statistik (cache)
124 ms — hämta tråd, inlägg och bilagor (db)
123 ms — ändringar (db)