Advanced Search

Results 1 to 5 of 5

Thread: Manipulating HTML elements in document.title

  1. #1
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Manipulating HTML elements in document.title

    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.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    If you set the document title using JavaScript using a code like the following:

    Code:
    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

  3. #3
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, thanks. I guess I can use an asterisk instead.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,704
    Thanks
    43
    Thanked 3,133 Times in 3,097 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by starlon View Post
    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:

    Code:
    document.title = 'SiteName • PageName';
    or the unicode scripted entity:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks. It works perfectly now.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •