JavaScript method to get the current page title (title)

  • 2020-05-26 07:44:30
  • OfStack

This example shows how JavaScript gets the title of the current web page (title). Share with you for your reference. The details are as follows:

document.title in JS gets the title of the current page


<!DOCTYPE html>
<html>
<head>
<title>ofstack.com</title>
</head>
<body>
current document's title is:
<script>
document.write(document.title);
</script>
</body>
</html>

The results are as follows:


current document's title is:ofstack.com

This section provides an example of how to use the js code to modify and read the title of a web page.
The test passed under ie6 and ff 2.0.

Code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> The title 1</title>
</head>
<body>
<script type="text/javascript">
<!--
var t=document.title;
alert(t);
document.title=" Changed title 2";
//-->
</script>
</body>
</html>

I hope this article has been helpful to your javascript programming.


Related articles: