值
一個包含文件標題的字串。如果標題被 document.title 的設定覆蓋,則包含該值。否則,它包含在 <title> 元素中指定的標題。
js
document.title = newTitle;
newTitle 是文件的新標題。此賦值會影響 document.title 的返回值、文件顯示的標題(例如,在視窗或標籤頁的標題欄中),並且還會影響文件的 DOM(例如,HTML 文件中 <title> 元素的內容)。
示例
假設文件的 <head> 如下所示:
html
<head>
<meta charset="UTF-8" />
<title>Hello World!</title>
</head>
js
console.log(document.title); // "Hello World!"
document.title = "Goodbye World!"; // Page title changed
console.log(document.title); // "Goodbye World!"
規範
| 規範 |
|---|
| HTML # document.title |
瀏覽器相容性
載入中…