UMD Web Utilities Library
    Preparing search index...

    Function isExternalUrl

    • Checks if a given URL points to a different hostname than the current page.

      This utility is useful for determining whether a link should open in a new tab or have special styling/behavior for external links.

      Parameters

      • url: string

        The URL to check (can be absolute or relative)

      Returns boolean

      True if the URL is external (different hostname), false otherwise

      // On https://beta.localhost.dev/components

      // Same hostname - returns false
      isExternalUrl('https://beta.localhost.dev/giving'); // false
      isExternalUrl('/components/navigation'); // false
      isExternalUrl('../about'); // false

      // Different hostname - returns true
      isExternalUrl('https://giving.umd.edu'); // true
      isExternalUrl('https://www.google.com'); // true

      // Invalid URLs - returns false
      isExternalUrl('not a url'); // false
      isExternalUrl(''); // false