Solved

Add Target Attribute to a Link

Posted on 2010-09-23
4
513 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
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…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

717 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