How to get current page title in JavaScript?

beginer
beginer
242 Points
71 Posts

How to get current page title in JavaScript?

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

Share:   fb twitter linkedin
Answers
Priya
Priya
Member
156 Points
43 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
110 Points
35 Posts
         

try this too

var title = document.getElementsByTagName("title")[0].innerHTML;
Posted On: 14-Sep-2021 04:19
Smith
Smith
Participant
622 Points
141 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