Skip to content

Commit

Permalink
Iframe: Fix relative wp-content URLs (#66751)
Browse files Browse the repository at this point in the history
Unlinked contributors: tambourine-man, Pat-Relentless, nicolasleroy.

Co-authored-by: Soean <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: getdave <[email protected]>
Co-authored-by: cweiske <[email protected]>
Co-authored-by: peterwilsoncc <[email protected]>
  • Loading branch information
7 people authored Nov 7, 2024
1 parent 9671f7c commit ab6e729
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 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 Expand Up @@ -272,6 +288,7 @@ function Iframe( {
<html>
<head>
<meta charset="utf-8">
<base href="${ window.location.origin }">
<script>window.frameElement._load()</script>
<style>
html{
Expand Down

0 comments on commit ab6e729

Please sign in to comment.