Solved

Add Target Attribute to a Link

Posted on 2010-09-23
4
508 Views
Last Modified: 2012-05-10
Greetings

I am trying to add the target attribute to links in an rss feed.

Here is my code:

<cfset rssContent = REReplace(rssContent,'<a href="http://[^"]+">','<a href="http://[^"]+" target="_blank">','ALL')>

It is adding the target attribute but it's destroying the link information.

Thanks
0
Comment
Question by:RayBakker
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 33745597
Try this:
<cfset rssContent = REReplace(rssContent,'(<a href="http://[^"]+")>','\1 target="_blank">','ALL')>

Open in new window

0
 
LVL 36

Expert Comment

by:SidFishes
ID: 33745673
or you can simply replace the closing >

<cfset out = replacenocase(rssContent, ">",  " target=""_blank"">","ALL")>


btw - in either case you should use the replaceNoCase or reReplaceNoCase if you don't have control of the source of the input as replace is case sensitive it will miss

google.com vs Google.com

0
 

Author Closing Comment

by:RayBakker
ID: 33747342
Works perfectly. Thank you.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33748605
NP. Glad to help  :)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sharepoint to FTP? 3 62
Jquery/JS : How to detect a telephone number or email within a string? 8 46
Passing value to a stored procedure 8 89
awk problem filtering combo 12 26
A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now