admin管理员组

文章数量:1313121

I am have been reading material on JavaScript and there are two ways of accessing the title of the page:

  1. The window.title property
  2. The document.title property

But when applying, the second only works. I am unable to understand why there are two titles and why both of them don't work.

I am have been reading material on JavaScript and there are two ways of accessing the title of the page:

  1. The window.title property
  2. The document.title property

But when applying, the second only works. I am unable to understand why there are two titles and why both of them don't work.

Share Improve this question asked Jun 19, 2013 at 1:40 M. Ahmad ZafarM. Ahmad Zafar 4,9394 gold badges34 silver badges45 bronze badges 3
  • There aren't. window.title is not a universal property, whereas document.title is. Fire up you're browser's console, and type "window.t" and see what it tries to autoplete with. There will be no "title" in that list. – Mike 'Pomax' Kamermans Commented Jun 19, 2013 at 1:44
  • Is window.title a depreciated property then? – M. Ahmad Zafar Commented Jun 19, 2013 at 2:04
  • 2 document is in window: window.document.title is the same as document.title – elclanrs Commented Jun 19, 2013 at 2:04
Add a ment  | 

1 Answer 1

Reset to default 10

window.document.title is correct.

window.title is incorrect, because the window object doesn't have a title property (all the properties of window are down the left side, you'll see title isn't there).

本文标签: javascriptDifference between windowtitle and documenttitleStack Overflow