isSameOrigin
Check whether two URLs share the same origin (protocol, host, and port), a common guard before trusting cross-document navigation.
Usage
isSameOrigin checks whether two URLs share the same origin.
import { isSameOrigin } from '@movk/core'
isSameOrigin('https://example.com/a', 'https://example.com/b') // true
isSameOrigin('https://example.com', 'https://sub.example.com') // false
isSameOrigin('https://example.com', 'http://example.com') // false
API
isSameOrigin(url1, url2)
Check whether two URLs share the same origin.
Parameters
url1
string required
The first URL.
url2
string required
The second URL.
Returns
returns
boolean
Whether the two URLs have the same origin.
Changelog
No recent changes