Change Browser Title in AJAXable site

When working with AngularJS, BackboneJS or any Javascript MV* framework, routing page will not change the Browser Title automatically. So to change the Browser Title we need to use the document.title  keyword of javascript.

Here, I have explained how to change browser title in a site which is developed with Javascript MV* framework. This is same as in AJAX site where we refresh the content of the page only and not the page. First, I was bit confused with the request but then I have checked on Mozilla’s developer site and found that there is an option to change the title with document.title  keyword.

Change Browser Title

We can get browser title with document.title  and can set a title of browser with document.title = “New Title”;

In a project we can write a function as:

function changeTitle(name){
	document.title = name;
}

Now, we can call the changeTitle()  when we route a page in any of the Javascript MV* framework based project.

Specification:

DOM Level 2 HTML: document.title

Web/ UI & Front-end developer based in Ahmedabad, GJ, India. Here to help/ discuss community to spread web awareness.

Leave a reply:

Your email address will not be published.