Open external link in a new tab when embedded in an iframe (#2846)

This commit is contained in:
Samy Pessé
2025-02-18 13:41:45 +01:00
committed by GitHub
parent b29a885bae
commit 359bb979f8
2 changed files with 12 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'gitbook': patch
---
Fix opening external links when the GitBook page is embedded in an iframe
@@ -47,6 +47,13 @@ export const Link = React.forwardRef(function Link(
});
}
// When the page is embedded in an iframe, for security reasons other urls cannot be opened.
// In this case, we open the link in a new tab.
if (isExternal && window.self !== window.top) {
event.preventDefault();
window.open(href, '_blank');
}
domProps.onClick?.(event);
};