-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* handle markdown links * handle all links * remove comment
- Loading branch information
1 parent
d39e2a7
commit e7e38c6
Showing
3 changed files
with
54 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const interceptExternalLinks = () => { | ||
const handleLinkClick = (event: MouseEvent) => { | ||
const target = event.target as HTMLAnchorElement; | ||
|
||
// Check if the clicked element is a link | ||
if (target.tagName === 'A' && target.href) { | ||
const isExternalLink = !target.href.startsWith(window.location.origin); | ||
|
||
if (isExternalLink) { | ||
event.preventDefault(); | ||
console.log("External link clicked:", target.href); | ||
|
||
// Open external link in a new window with specified position and size | ||
window.open( | ||
target.href, | ||
'_blank', | ||
'noopener,noreferrer,width=800,height=600,left=100,top=100' | ||
); | ||
} | ||
} | ||
}; | ||
|
||
// Add event listener to capture all clicks on links | ||
document.addEventListener('click', handleLinkClick); | ||
|
||
// Return a cleanup function to remove the event listener when needed | ||
return () => { | ||
document.removeEventListener('click', handleLinkClick); | ||
}; | ||
}; | ||
|
||
export default interceptExternalLinks; | ||
|