Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. function isInternalLink(href) {
  2. try {
  3. /* full URL i.e. has protocol */
  4. let url = new URL(href)
  5. return url.origin === window.location.origin
  6. } catch {
  7. return !href.startsWith('//') ||
  8. (href.startsWith('//') && (window.location.protocol + href).startsWith(window.location.origin))
  9. }
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement