Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul Blair 466 posts 731 karma points
    Aug 19, 2009 @ 02:21
    Paul Blair
    0

    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

  • Paul Blair 466 posts 731 karma points
    Aug 19, 2009 @ 02:27
    Paul Blair
    0

    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

  • dandrayne 1138 posts 2262 karma points
    Aug 19, 2009 @ 12:03
    dandrayne
    0

    In xslt, you could try

    umbraco.library:Replace()

    I've not tested this, but you could attempt to replace

    <a href=" 

    with

    <a rel="nofollow" target="_blank" href="

    http://our.umbraco.org/wiki/reference/umbracolibrary/replace

    Worth a shot!

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 19, 2009 @ 12:35
    Dirk De Grave
    2

    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

    <script type="text/javascript">
            $(document).ready(function() {
                    $('#divId a').attr('rel', 'nofollow');
            });
    </script>

     

    /Dirk

     

  • dandrayne 1138 posts 2262 karma points
    Aug 19, 2009 @ 13:05
    dandrayne
    1

    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.

    <script type="text/javascript">
            $
    (document).ready(function() {
                    $
    ('#divId a').attr('rel', 'nofollow').attr('target', '_blank');
           
    });
    </script>
  • Paul Blair 466 posts 731 karma points
    Aug 19, 2009 @ 22:48
    Paul Blair
    0

    Thanks for the suggestions guys - I'll be giving it a go next week sometime...

  • Paul Blair 466 posts 731 karma points
    Aug 26, 2009 @ 11:08
    Paul Blair
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft