---
title: "tinymce.util.URI"
description: "This class handles parsing, modification and serialization of URI/URL strings."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.util.uri/"
md_url: "https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.util.uri/index.md"
version: "latest"
last_updated: "2022-06-27T01:45:26Z"
tokens: 1190
---
# tinymce.util.URI

This class handles parsing, modification and serialization of URI/URL strings.

## Summary

### Constructors

| Name | Summary | Defined by |
| --- | --- | --- |
| [URI()](#URI) | Constructs a new URI instance. | `URI` |

### Methods

| Name | Summary | Defined by |
| --- | --- | --- |
| [getURI()](#getURI) | Returns the full URI of the internal structure. | `URI` |
| [isDomSafe()](#isDomSafe) | Check to see if a URI is safe to use in the Document Object Model (DOM). This will return true if the URI can be used in the DOM without potentially triggering a security issue. | `URI` |
| [isSameOrigin()](#isSameOrigin) | Determine whether the given URI has the same origin as this URI.  Based on RFC-6454. Supports default ports for protocols listed in DEFAULT_PORTS.  Unsupported protocols will fail safe: they won’t match, if the port specifications differ. | `URI` |
| [setPath()](#setPath) | Sets the internal path part of the URI. | `URI` |
| [toAbsPath()](#toAbsPath) | Converts a relative path into a absolute path. | `URI` |
| [toAbsolute()](#toAbsolute) | Converts the specified URI into a absolute URI based on the current URI instance location. | `URI` |
| [toRelPath()](#toRelPath) | Converts a absolute path into a relative path. | `URI` |
| [toRelative()](#toRelative) | Converts the specified URI into a relative URI based on the current URI instance location. | `URI` |

## Constructors

### URI

```javascript
public constructor function URI(url: String, settings: Object)
```
Constructs a new URI instance.

#### Parameters

- `url (String)` - URI string to parse.
- `settings (Object)` - Optional settings object.

## Methods

### getURI()

```javascript
getURI(noProtoHost: Boolean)
```
Returns the full URI of the internal structure.

#### Parameters

- `noProtoHost (Boolean)` - Optional no host and protocol part. Defaults to false.

### isDomSafe()

```javascript
isDomSafe(uri: String, context: Object, options: Object): Boolean
```
Check to see if a URI is safe to use in the Document Object Model (DOM). This will return
true if the URI can be used in the DOM without potentially triggering a security issue.

#### Parameters

- `uri (String)` - The URI to be validated.
- `context (Object)` - An optional HTML tag name where the element is being used.
- `options (Object)` - An optional set of options to use when determining if the URI is safe.

#### Return value

- `Boolean` - True if the URI is safe, otherwise false.

### isSameOrigin()

```javascript
isSameOrigin(uri: tinymce.util.URI): Boolean
```
Determine whether the given URI has the same origin as this URI.  Based on RFC-6454.
Supports default ports for protocols listed in DEFAULT_PORTS.  Unsupported protocols will fail safe: they
won’t match, if the port specifications differ.

#### Parameters

- `uri (URI)` - Uri instance to compare.

#### Return value

- `Boolean` - True if the origins are the same.

### setPath()

```javascript
setPath(path: String)
```
Sets the internal path part of the URI.

#### Parameters

- `path (String)` - Path string to set.

### toAbsPath()

```javascript
toAbsPath(base: String, path: String)
```
Converts a relative path into a absolute path.

#### Parameters

- `base (String)` - Base point to convert the path from.
- `path (String)` - Relative path to convert into an absolute path.

### toAbsolute()

```javascript
toAbsolute(uri: String, noHost: Boolean): String
```
Converts the specified URI into a absolute URI based on the current URI instance location.

#### Examples

```javascript
// Converts an relative URL to an absolute URL url will be http://www.site.com/dir/somedir/somefile.htm
const url = new tinymce.util.URI('http://www.site.com/dir/').toAbsolute('somedir/somefile.htm');
```

#### Parameters

- `uri (String)` - URI to convert into a relative path/URI.
- `noHost (Boolean)` - No host and protocol prefix.

#### Return value

- `String` - Absolute URI from the point specified in the current URI instance.

### toRelPath()

```javascript
toRelPath(base: String, path: String)
```
Converts a absolute path into a relative path.

#### Parameters

- `base (String)` - Base point to convert the path from.
- `path (String)` - Absolute path to convert into a relative path.

### toRelative()

```javascript
toRelative(uri: String): String
```
Converts the specified URI into a relative URI based on the current URI instance location.

#### Examples

```javascript
// Converts an absolute URL to an relative URL url will be somedir/somefile.htm
const url = new tinymce.util.URI('http://www.site.com/dir/').toRelative('http://www.site.com/dir/somedir/somefile.htm');
```

#### Parameters

- `uri (String)` - URI to convert into a relative path/URI.

#### Return value

- `String` - Relative URI from the point specified in the current URI instance.
