Thanks Karl!!! That's WAY better than what I came up with. I knew there was
a better way.

  _____  

From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Karl Swedberg
Sent: Thursday, October 18, 2007 12:51 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Create link around email anywhere on page?


Hi Andy, 

Although I'm not sure about performance and I'm guessing that the regular
expression could be improved, I have a 3-liner that should work in most
cases:

var markup = $('body').html();
var modMarkup = markup.replace(/([EMAIL PROTECTED],4})/g,'<a
href="mailto\:$1">$1<\/a>')
$('body').html(modMarkup);

Hope that helps.


--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Oct 18, 2007, at 12:04 PM, Andy Matthews wrote:


This is what I've got so far. I've got the individual strings isolated, but
I'm not really sure how to them into the page where they belong.

HTML
----------
<body>
<p>
[EMAIL PROTECTED] Kilohertz [EMAIL PROTECTED],
transistorized. Converter [EMAIL PROTECTED] services extended patch,
interface [EMAIL PROTECTED]
</p>
</body>

JS
------------
$(document).ready(function(){
// create array of individual strings by splitting out the
// contents of the body tag
var textArr = $('body').text().split(' ');
// loop over this array to check for strings containing an @
for (s=0;s<textArr.length;s++) {
// temp var
var str = textArr[s];
// does this specific string contain an @?
if (str.match('@') == '@') {
// it does, but we want to make sure that there's no
// periods or commas at the end of the string
var final = str.replace(/[\.,]$/,'');
alert(final);
}
}
});

  _____  

From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Andy Matthews
Sent: Thursday, October 18, 2007 10:29 AM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Create link around email anywhere on page?


Just to clarify, I'm looking to convert this HTML:

Logistically remote [EMAIL PROTECTED], infrared extended cable prototype
feedback, software, encapsulated 
port element technician development logistically
[EMAIL PROTECTED]

to this:

Logistically remote <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>,
infrared extended cable prototype feedback, software, encapsulated port
element technician development logistically <a
href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a
>.

  _____  

From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Andy Matthews
Sent: Thursday, October 18, 2007 10:16 AM
To: [jQuery]
Subject: [jQuery] Create link around email anywhere on page?


My company has some poorly written legacy code that outputs email fields to
the page. Problem is that the email field variable named is itself variable.
We don't know in advance that any specific field contains an email or not.

So what I'd like to do is after the page is rendered, parse through the page
and make a mailto link out of any string which contains an @ symbol.

Does anyone have something like this already, or might have suggestions as
to where to start with writing it myself?

____________________________________

Andy Matthews
Senior ColdFusion Developer

<dealerskinslogo.bmp>

Office: 877.707.5467 x747
Direct: 615.627.9747
Fax: 615.467.6249
[EMAIL PROTECTED]
www.dealerskins.com <http://www.dealerskins.com/> 


Reply via email to