aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/node/baseuri/index.md
blob: 053fadb86627a51fb90197c93c1e50ac82dac1f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: Node.baseURI
slug: Web/API/Node/baseURI
tags:
  - Node
  - プロパティ
  - 読み取り専用
browser-compat: api.Node.baseURI
translation_of: Web/API/Node/baseURI
---
{{APIRef("DOM")}}

**`baseURI`** は {{domxref("Node")}} インターフェイスの読み取り専用プロパティで、このノードを含む文書の絶対的なベース URL を返します。

ベース URL はブラウザーが絶対 URL を必要とするときに、相対 URL を解決するために使用されます。例えば、 HTML の {{HTMLElement("img")}} 要素の `src` 属性や、 SVG の `xlink:href``href` 属性を処理する場合などです。

このプロパティは読み取り専用ですが、値はプロパティがアクセスされるたびにアルゴリズムで決まりますので、状況が変化すると変化することがあります。

ベース URL は次のように決まります。

1. 既定で、ベース URL は文書の位置({{domxref("window.location")}} で指定された通り)となります。
2. これが HTML 文書であり、文書に {{HTMLElement("Base")}} 要素があった場合、*最初の* `Base` 要素の `href` の値があれば、代わりに使用されます。

## 値

{{domxref("Node")}} のベース URL を表す文字列です。

## 例

### \<base> なし

```html
<output>Not calculated</output>
```

```js
const output = document.getElementsByTagName("output")[0];
output.value = output.baseURI;
```

{{EmbedLiveSample("Without <base>", "100%", 40)}}

### \<base> あり

```html
<base href="https://developer.mozilla.org/modified_base_uri/">
<output>Not calculated</output>
```

```js
const output = document.getElementsByTagName("output")[0];
output.value = output.baseURI;
```

{{EmbedLiveSample("With <base>", "100%", 40)}}

## 仕様書

{{Specifications}}

## ブラウザーの互換性

{{Compat}}

## 関連情報

- {{HTMLElement("base")}} 要素