View Full Version : Manipulating HTML elements in document.title

04-04-2009, 07:37 AM
If I start a page like "<title>Sitename &bull; Sitepage</title>" the bullet shows up like it's supposed to in the title.

However, if I change document.title to something else with an html element like '&bull;' the actual text is shown instead of the bullet.

Do I need to escape or format these elements when putting them into document.title? I've tried a couple of things already, like URL encoding and escaping, but maybe I'm missing something.

I've only tried in Firefox on Fedora 10 and XP, and IE 6.

04-04-2009, 10:25 AM
If you set the document title using JavaScript using a code like the following:

document.title = "dynamic title";

The value you set will be treated as string not as HTML markup and as a result the HTML character entity that you try to use will be displayed as is.. But if you mention a title in your HTML page using within the title tag then it allows HTML character entities.

Hope this help

04-04-2009, 10:41 AM
Ok, thanks. I guess I can use an asterisk instead.

04-04-2009, 12:18 PM
Ok, thanks. I guess I can use an asterisk instead.

Well no. I mean you can, but you may also use the literal bullet character:

document.title = 'SiteName • PageName';

or the unicode scripted entity:

document.title = 'SiteName \u2022 PageName';

You could probably even clone an invisible text node that uses the &bull; entity, but in a case like this, that would be overkill.

04-04-2009, 09:09 PM
Thanks. It works perfectly now.