I'd have to second Dirk's emotion, on second thoughts. Unobtrusive, less complicated and with less chance of things going wrong if the <a href isn't formed in exactly the way you specify in the xml.
Also, target="_blank" is deprecated, so adding it in via javascript won't break html validation.
I have actually also ended up having to do this for another site based on VB6! (yes, they still exist). It's moments like these you really appreciate .NET & Umbraco
For anyone who is interested here is the VB Script:
Function cleanHTML(byval vData , iStart ) Dim iStartTag Dim iEndTag Dim sAnchor Dim sNewAnchor dim sNewData
Adding tags to links added in RTE
Can anyone think of a smart way of making links added in the HTML editor have certain tags included (e.g. <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:EN-US; mso-fareast-language:EN-US;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 72.0pt 72.0pt 72.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> rel="nofollow" target="_blank")
I would also like to make sure these are present even when the user has entered content in HTML mode.
I could try trapping the onPublish event and doing some HTML parsing unless there is a better way...
Cheers
Paul
that should of read like this:
Can anyone think of a smart way of making links added in the HTML editor have certain tags included (e.g. rel="nofollow" target="_blank")
I would also like to make sure these are present even when the user has entered content in HTML mode.
I could try trapping the onPublish event and doing some HTML parsing unless there is a better way...
Cheers
Paul
In xslt, you could try
I've not tested this, but you could attempt to replace
with
http://our.umbraco.org/wiki/reference/umbracolibrary/replace
Worth a shot!
Or wrap the rte in template in a div, give it an id, and use some jquery to add some extra attributes to all links (a tags) within the specific div
/Dirk
I'd have to second Dirk's emotion, on second thoughts. Unobtrusive, less complicated and with less chance of things going wrong if the <a href isn't formed in exactly the way you specify in the xml.
Also, target="_blank" is deprecated, so adding it in via javascript won't break html validation.
Thanks for the suggestions guys - I'll be giving it a go next week sometime...
I have actually also ended up having to do this for another site based on VB6! (yes, they still exist). It's moments like these you really appreciate .NET & Umbraco
For anyone who is interested here is the VB Script:
Function cleanHTML(byval vData , iStart )
Dim iStartTag
Dim iEndTag
Dim sAnchor
Dim sNewAnchor
dim sNewData
snewdata=vdata
iStartTag = InStr(iStart, vData, "<a ")
If iStartTag >= 1 Then
iEndTag = InStr(iStartTag, vData, ">")
sAnchor = Mid(vData, iStartTag, iEndTag - iStartTag+1)
sNewAnchor = removeTag(sAnchor, "rel=")
sNewAnchor = removeTag(sNewAnchor, "target=")
sNewAnchor = Replace(sNewAnchor, "<a ", "<a rel=""nofollow"" target=""_blank"" ")
sNewData= Replace(sNewData, sAnchor, sNewAnchor)
sNewData= cleanHTML(sNewData, iEndTag)
End If
cleanHTML = sNewData
End Function
Function removeTag( vData , sTag )
Dim iStart
Dim iEnd
iStart = InStr(vData, sTag)
If iStart >= 1 Then
iEnd = InStr(iStart, vData, " ")
If iEnd=0 Then iEnd = InStr(iStart, vData, ">")
removeTag = Replace(vData, Mid(vData, iStart, iEnd - iStart), "")
else
removeTag = vData
End If
End Function
is working on a reply...