---
title: "getDomain"
description: "从完整 URL 中提取域名部分（含协议），适用于跨域检测和 URL 分析场景。"
seo_title: "getDomain"
seo_description: "Extract the hostname from a URL string, returning the domain portion so you can compare, filter, or display the origin of a link."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/get-domain"
---
# getDomain

> 从完整 URL 中提取域名部分（含协议），适用于跨域检测和 URL 分析场景。

## 用法

`getDomain` 函数用于获取 URL 的域名部分。

```ts
import { getDomain } from '@movk/core'

getDomain('https://sub.example.com/path') // 'sub.example.com'
getDomain('https://example.com:8080') // 'example.com'
```

## API

### `getDomain(url)`

获取 URL 的域名部分。

### 参数

**url** (`string`) *required*: URL 字符串。

### 返回值

**返回值** (`string`): 域名,解析失败返回空字符串。

## Changelog

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


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
