Document: title プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
document.title プロパティは、現在の文書の題名を取得または設定します。 存在する場合、<title> の値が既定値です。
値
文字列で、この文書の題名が入ります。題名が document.title に設定することで上書きされている場合は、その値が入ります。そうでなければ、 <title> 要素に指定された題名が入ります。
js
document.title = newTitle; newTitle は文書の新しい題名です。代入すると、 document.title の返値、文書に表示される題名(ウィンドウのタイトルバーやタブなど)、文書の DOM(HTML 文書の <title> 要素の内容など)にも反映されます。
例
html
<!doctype html> <html lang="ja"> <head> <meta charset="UTF-8" /> <title>Hello World!</title> </head> <body> <script> alert(document.title); // "Hello World!" と表示 document.title = "Goodbye World!"; alert(document.title); // "Goodbye World!" と表示 </script> </body> </html> 仕様書
| Specification |
|---|
| HTML> # document.title> |