Skip to content

Commit 359bb97

Browse files
authored
Open external link in a new tab when embedded in an iframe (#2846)
1 parent b29a885 commit 359bb97

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

.changeset/fluffy-beans-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': patch
3+
---
4+
5+
Fix opening external links when the GitBook page is embedded in an iframe

packages/gitbook/src/components/primitives/Link.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export const Link = React.forwardRef(function Link(
4747
});
4848
}
4949

50+
// When the page is embedded in an iframe, for security reasons other urls cannot be opened.
51+
// In this case, we open the link in a new tab.
52+
if (isExternal && window.self !== window.top) {
53+
event.preventDefault();
54+
window.open(href, '_blank');
55+
}
56+
5057
domProps.onClick?.(event);
5158
};
5259

0 commit comments

Comments
 (0)