Solved

Add Target Attribute to a Link

Posted on 2010-09-23
4
510 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Edit a page at wix.com 8 85
regex code: words must be 6 to 8 characters long ? 2 35
Grunt script for Build Process 1 67
REGEXEXTRACT in google sheets 2 17
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

730 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