Javascript Code to Scrolling Page Title

Here I am going to share the Javascript code for scrolling the page title of any web page.

You can change the page title by simply set document title property using javascript

document.title = "modified text";

Scrolling Page Title Code

<html>
  <head>
   <title>Test Sample Moving Page Title. </title>
  
    <script type="text/javascript">
      var msg  = document.title;
      var speed = 150;
      var endChar = "... ";
      var pos = 0;
      
      function moveTitle()
      {
       	var ml = msg.length;
      		
      	title = msg.substr(pos,ml) + endChar + msg.substr(0,pos);
    	document.title = title;
      	
        pos++;
    	if (pos > ml) pos=0;
        window.setTimeout("moveTitle()",speed);
      }
  
      moveTitle();
  </script>
  </head>
  <body>
     See the moving page title browser title bar
  </body>
</html>

You can change the scroll speed by changing the value of variable “speed”. Above it is 150, which means that each character will change it’s position in every 150 milliseconds.

You can change the “msg” variable value to give a custom message text. Above it is assigned to a document title, it is a text inside the title tag.

Add a Comment

Your email address will not be published. Required fields are marked *

Close Bitnami banner