I am have been reading material on JavaScript and there are two ways of accessing the title
of the page:
- The
window.title
property - 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:
- The
window.title
property - 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, whereasdocument.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 inwindow
:window.document.title
is the same asdocument.title
– elclanrs Commented Jun 19, 2013 at 2:04
1 Answer
Reset to default 10window.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).