Make WordPress Core

Changeset 63400


Ignore:
Timestamp:
08/30/2026 10:31:20 PM (25 hours ago)
Author:
peterwilsoncc
Message:

Embeds: Update click handler to follow deeply nested links.

Update linkClickHandler() to follow links with nested sub elements within the _top window, for example <a href="http://wordpress.org"><span><span>WordPress</span></span>></a>.

Previously the link handler only handled links with single nested elements, links further nested would open within the iframe.

Developed in https://github.com/WordPress/wordpress-develop/pull/13244.

Props khokansardar, swissspidy, westonruter.
Fixes #65947.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/embed-template.js

    r52132 r63400  
    157157                 */
    158158                function linkClickHandler( e ) {
    159                         var target = e.target,
    160                                 href;
    161                         if ( target.hasAttribute( 'href' ) ) {
    162                                 href = target.getAttribute( 'href' );
    163                         } else {
    164                                 href = target.parentElement.getAttribute( 'href' );
    165                         }
     159                        /*
     160                         * The href property resolves to an absolute URL, which the parent window requires.
     161                         * Elements whose href is not a string, such as SVG anchors, are skipped.
     162                         */
     163                        var link = e.target.closest( '[href]' ),
     164                                href = 'string' === typeof link?.href ? link.href : null;
    166165
    167166                        // Only catch clicks from the primary mouse button, without any modifiers.
Note: See TracChangeset for help on using the changeset viewer.