Log in

View Full Version : get document <Title>



jimbowvu80s
11-24-2009, 09:21 PM
I am trying to get the document title so I can display it in the body section of a page.

<title>This is the name of the document</title>

Here's my javascript:

<script type="text/javascript">
document.getElementById.title="doc_title";
document.write("This is the " + doc_title);
</script>

I don't think I have the correct elements because it doesn't display the "doc_title" Also, wasn't sure if this could be done with some html.

Thanks for your help.

bluewalrus
11-24-2009, 09:27 PM
That doesn't have an ID as your calling it. That's an element try giving it an id that is title like
<title id="title">w</title>. Then i think you want to switch the order of your equation around also. This assumes also that the title tag takes ids I don't know if it does.


var doc_title = document.getElementById.title.value;

I don't know much javascript though so if that doesn't work wait for someone that does.

Schmoopy
11-24-2009, 09:41 PM
Simple way of accessing the title is:



document.write('This is the ' + document.title);

jimbowvu80s
11-24-2009, 09:56 PM
Thanks Schmoopy. That works perfectly.