How can I get the title of an HTML page with JavaScript?
231
votes
3 Answers
370
votes
17
votes
10
votes
Can use getElementsByTagName
var x = document.getElementsByTagName("title")[0];
alert(x.innerHTML)
// or
alert(x.textContent)
// or
document.querySelector('title')
Edits as suggested by Paul
document.titleand accessing thetitleelement directly, see here. - Paul