How to get the title and full URL of a document in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Javascript HTML DOM has provided some basic methods to access and manipulate the HTML data. To find the title and URL of a document, javascript has provided document.title and document.URL respectively. Let's discuss them individually.

Title of a document

To get the title of a document javascript HTML DOM has provided document.title method. 

 In the following example, the title of the document is found out and displayed as shown in the output.

Example

Live Demo

<html>
<head>
   <title>Tutorix</title>
</head>
<body>
<script>
   document.write("The title of the document is" +" "+ document.title);
</script>
</body>
</html>

Output

Tutorix


URL of a document

To get the URL of a document javascript HTML DOM has provided document.URL method.

 In the following example, the URL of the document is found out and displayed in the output.

Example

Live Demo

<html>
<body>
<script>
   document.write("The URL of the document is:" + " " +document.URL)
</script>
</body>
</html>

Output

The URL of the document is: https://www.tutorialspoint.com/cg/assets/ovPEzF.php
raja
Published on 25-Jul-2019 18:36:17
Advertisements