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
<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
<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