3

I have coded myself into a corner. Does anyone know the answer? Thanks!

MPelletier
  • 16,256
  • 15
  • 86
  • 137
  • 2
    This is easily found using Google. What have you tried and what doesn't work? – strager Sep 30 '09 at 20:47
  • possible duplicate: http://stackoverflow.com/questions/180103/jquery-how-to-change-title-of-document-during-ready – Starx Jan 07 '11 at 06:38

5 Answers5

10

This will work also:

$('title').text("Boo");
Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192
  • Not sure why I couldn't get the document.title or this.title to take, but Vincent's method did the trick. I should've been more specific in what I was doing, I suppose, in my question. I am grabbing the contents of a div near the end of the html body and writing it out to the page title. If I figure out what the problem was I'll post it up here. –  Sep 30 '09 at 21:22
  • 3
    doesn't work in IE8 - "Unexpected call to method or property access." – Scott Evernden Mar 10 '11 at 20:21
  • 2
    This is not a cross browser solution. The `$(document).attr('title', 'new title');` mentioned below is better. – Gazzer Mar 29 '12 at 09:32
  • Any ideas as to how an approach like this might affect Google indexing the site? I know page title is important... Does google include the original page title or the new one? – Sam May 27 '12 at 14:39
9
document.title = 'new value';

Is this not working for you?

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • Strangely no. I can read the value of document.title, but I cannot seem to change the display. I have tried setting it in the head of the document as well as in the body. –  Sep 30 '09 at 20:54
  • 2
    @subbit, Are you sure your browser isn't preventing you from changing the title? Check your browser's options. – strager Sep 30 '09 at 21:01
4

Try:

$(document).ready(function() {
    this.title = 'foo'
})
Crescent Fresh
  • 115,249
  • 25
  • 154
  • 140
  • This helped me. Sometimes (in FF and Chrome), the things is that the stuff is tried even it the site is not fully loaded. Hence, it might not work as expected... – Alfabravo Dec 10 '10 at 22:15
3

Maybe this will help you:

$(document).attr('title', 'new title');
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
LX7
  • 609
  • 1
  • 6
  • 22
1

$('title').text("Boo"); is not good idea because IE8 has problem with that.
this bug is reported Here but jQuery developers did not solve that and their solution is Use document.title='Boo';.

my idea is that

  1. using document.title is best option and it is cross browser solution
  2. but if you are used to use jQuery you can use $(document).attr('title', 'new title');. i tested it and has no problem with major browsers and IE8
iman
  • 6,062
  • 1
  • 19
  • 23