Updating The HTML <title> Tag With JavaScript

March 26th, 2013 - Posted by Steve Marks to (X)HTML / CSS, Javascript / jQuery, Web Development.

Sometimes we might not know the full title of a HTML page when the page first loads, meaning that we will need to set it dynamically. I found myself in this scenario recently and needed to set the title using JavaScript. I couldn’t believe how easy it was to do and wanted to share the result so others can do the same thing:

document.title = 'This is my new title';

Yup, that’s it! I told you it was easy.

Note: Bear in mind that search engines don’t execute JavaScript and therefore won’t take your updated title into account. Just be aware of this if you’re wary of the pages impact in serch engine rankings.

This entry was posted on Tuesday, March 26th, 2013 at 7:19 am by +Steve Marks and is filed under (X)HTML / CSS, Javascript / jQuery, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first