How to get current page title in JavaScript?

beginer
beginer
1544 Points
52 Posts

How to get current page title in JavaScript?

Views: 3708
Total Answered: 3
Total Marked As Answer: 3
Posted On: 11-Sep-2021 23:21

Share:   fb twitter linkedin
Answers
Priya
Priya
1194 Points
33 Posts
         

We can use Html DOM title property to get title of the page as:

var title = document.title;
Posted On: 11-Sep-2021 23:23
edx
edx
506 Points
24 Posts
         

try this too

var title = document.getElementsByTagName("title")[0].innerHTML;
Posted On: 14-Sep-2021 04:19
Smith
Smith
2890 Points
78 Posts
         

Try code sample:

<html>
    <head>
        <title>My Nice Page Title</title>
    </head>
    <body>
        <p id="demo"></p>
        <script>
            document.getElementById("demo").innerHTML = document.title;
        </script>
    </body>
</html>
Posted On: 14-Sep-2021 04:22
 Log In to Chat