Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isInternalLink(href) {
- try {
- /* full URL i.e. has protocol */
- let url = new URL(href)
- return url.origin === window.location.origin
- } catch {
- return !href.startsWith('//') ||
- (href.startsWith('//') && (window.location.protocol + href).startsWith(window.location.origin))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement