• Resolved Paul Carter-Quayle

    (@paulcarterservices)


    I am unable to open url links in a new tab via the content text area using html. I’ve used the following html:

    <a  target="_blank" rel="noopener noreferrer">Fearless Heart</a>

    I contacted a member of your team via the live chat and they replied with the following:

    I’m afraid, Happy Tooltip extension is not allowing this behavior, it might be due to limitations in how the extension renders the HTML or security restrictions imposed upon it.

    Is there any further clarity or a suggested fix you could offer?

    I’ve tried the following JS script in the footer:

    //<![CDATA[
    jQuery(document).ready(function($) {
    $('a').each(function() {
    var a = new RegExp('/' + window.location.host + '/');
    if(!a.test(this.href)) {
    $(this).click(function(event) {
    event.preventDefault();
    event.stopPropagation();
    window.open(this.href, '_blank');
    });
    }
    });
    });
    //]]>

    And also the following php snippet in the footer:

    add_filter( 'the_content', function ( $content ) {
    // This snippet requires the DOMDocument class to be available.
    if ( ! class_exists( 'DOMDocument' ) ) {
    return $content;
    }
    if ( !is_single() || !in_the_loop() || !is_main_query() ) {
    return $content;
    }

    $dom = new DOMDocument();
    $load_content = mb_convert_encoding( $content, 'HTML-ENTITIES', 'UTF-8' );
    if ( empty( $load_content ) ) {
    return $content;
    }
    @$dom->loadHTML( $load_content );
    $links = $dom->getElementsByTagName( 'a' );

    foreach ( $links as $link ) {
    if ( strpos( $link->getAttribute( 'href' ), home_url() ) !== false ) {
    continue;
    }
    $old_link = $link->C14N();
    $link->setAttribute( 'target', '_blank' );
    $link->setAttribute( 'rel', 'noopener noreferrer' );

    $content = str_replace( $old_link, $link->C14N(), $content );
    }

    return $content;
    } );

    However neither work for the hover tooltip text. Please could you let me knwo your thoughts and whether you can suggest a fix or a workaround?

    Thank you kindly for your consideration ??

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Paul Carter-Quayle

    (@paulcarterservices)

    I have also tried the following JS script snippet to see if this would work:

    jQuery(document).ready(function($) {
    jQuery('.ha-advanced-tooltip-content a[href]').attr('target', '_blank');
    });

    However it still doesn’t work. Is this code correct or is there anything else you can recommend to force links in tooltips to open in a new tab?

    I’ve also explored troubleshooting by disabling all plugins (except core plugins) and renabling one by one to see if there were any plugin conflicts, however it doesn’t appear there are any conflicts so I really hope you can offer suggestions to help resolve this.

    Thank you kindly in advance ??

    Thread Starter Paul Carter-Quayle

    (@paulcarterservices)

    Here is the fix (kindly provided by the author of the ‘External Links – nofollow, noopener & new window‘ plugin) for anyone experiencing the same issue…

    jQuery(document).ready(function() {
    // Attach an event listener to all 'a' elements inside any '.ha-advanced-tooltip-content' div
    jQuery(document).on('click', 'a', function(event) {
    // Check if the clicked link is a child of a div with class 'ha-advanced-tooltip-content'
    if (jQuery(this).closest('.ha-advanced-tooltip-content').length > 0) {
    // Prevent the default action of the link
    event.preventDefault();
    // Add target="_blank" to the link to open in a new tab
    jQuery(this).attr('target', '_blank');
    // Open the link in a new window
    window.open(jQuery(this).attr('href'), '_blank');
    }
    });
    });

    Phew… I am relieved to arrive at a solution after many hours of troubleshooting. I hope the above code helps others too.

    Plugin Support Md. Anower Hossain

    (@anowerhossain16)

    Hi @paulcarterservices,

    Thank you for sharing your work and code! It will definitely help others who are looking for this feature and solution.

    If you encounter any further issues, please feel free to let us know. You can also reach out directly to our technical support for any Pro-related inquiries.

    Have a great day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.