Problem
With JavaScript, how can I get the title of an HTML page?
Asked by ZA.
Solution #1
Use document.title:
MDN Web Docs
Answered by ZA.
Solution #2
Put in the URL bar and then click enter:
javascript:alert(document.title);
You can select and copy the text from the alert depending on the website and the web browser you are using.
Answered by No Mercy
Solution #3
Can use getElementsByTagName
var x = document.getElementsByTagName("title")[0];
alert(x.innerHTML)
// or
alert(x.textContent)
// or
document.querySelector('title')
Paul’s suggestions for changes
Answered by SuperNova
Solution #4
The h1 element now serves as the page title. This demonstrates how powerful javascript can be for both tiny and large projects.
Answered by Marcell Kraszni
Post is based on https://stackoverflow.com/questions/1057059/how-to-get-the-title-of-html-page-with-javascript