Copied to clipboard

Flag this post as spam?

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


  • BEWD 90 posts 303 karma points
    Sep 05, 2023 @ 11:24
    BEWD
    0

    (Opens in a new window) when Target is checked in RTE link

    Hi All

    Does anyone know if its possible to automatically append “(Opens in a new window)” to the alt attribute of links added via the RTE in Umbraco v8 only when the Target box is checked?

    Currently the only way I know how requires the author having to physically type it at the end of the Link title every time but we have 3 large sites with over 700 external links each so that’s going to be a lot of work. It doesn't need to print to the page, Or even be visible in the 'Link Title' section below but needs to print into the title attribute in the HTML.

    enter image description here

    They are Local Government websites and in the UK we have a legal obligation to meet Accessibility Regulations. This is something I would like to get ticked off my list. I have looked through TinyMCE documents and searched this forum but can’t see an answer anywhere. Has anyone attempted to do this?

    Thanks

    Ben

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Sep 05, 2023 @ 15:57
    Huw Reddick
    100

    The alt attribute isn't actually valid for <a> you should append it to the title attribute, which you could do with some javascript code in your view. SOmething like below

    // getting all anchor tags
    let links = document.getElementsByTagName('a');
    // looping through all the HTMLCollection links
    for (let index=0; index<links.length; index++){
       // accessing the target attribute from each element
       let target = links[index].target;
       if(target === "_blank"){
           let title = links[index].getAttribute('title')
           links[index].setAttribute('title', title + "Whatever you want to add");
       }
    }
    
  • BEWD 90 posts 303 karma points
    Sep 06, 2023 @ 18:25
    BEWD
    0

    Spot on Huw. Thank you very much for your help!

Please Sign in or register to post replies

Write your reply to:

Draft