Skip to content

Commit

Permalink
prevent click on links
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 7, 2024
1 parent d195508 commit 0a6a275
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ function Iframe( {
preventFileDropDefault,
false
);
// Prevent clicks on links from navigating away. Note that links
// inside `contenteditable` are already disabled by the browser, so
// this is for links in blocks outside of `contenteditable`.
iFrameDocument.addEventListener( 'click', ( event ) => {
if ( event.target.tagName === 'A' ) {
event.preventDefault();

// Appending a hash to the current URL will not reload the
// page. This is useful for e.g. footnotes.
const href = event.target.getAttribute( 'href' );
if ( href.startsWith( '#' ) ) {
iFrameDocument.defaultView.location.hash =
href.slice( 1 );
}
}
} );
}

node.addEventListener( 'load', onLoad );
Expand Down

0 comments on commit 0a6a275

Please sign in to comment.