---
title: "isSameOrigin"
description: "Check whether two URLs share the same origin (protocol, host, and port), a common guard before trusting cross-document navigation."
canonical_url: "https://core.mhaibaraai.cn/en/docs/utilities/url/is-same-origin"
---
# 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.

```ts
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

See commit history for [src/utilities/url/transform.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/transform.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/utilities/url/transform.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
