Skip to content

Function: isSameOrigin()

ts
function isSameOrigin(urlA, urlB): boolean;

Checks whether two URLs share the same origin (scheme + host + port). 判断两个 URL 是否同源(协议 + 主机 + 端口)。

Parameters

ParameterTypeDescription
urlAstringFirst URL / 第一个 URL
urlBstringSecond URL / 第二个 URL

Returns

boolean

True when origins match / 同源则为 true

Example

ts
isSameOrigin('https://a.com/x', 'https://a.com/y') // => true

Since

1.0.0

Released under the MIT License.