Results 1 to 4 of 4

Thread: get document <Title>

  1. #1
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default get document <Title>

    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.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    That doesn't have an ID as your calling it. That's an element try giving it an id that is title like
    Code:
     <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.
    Code:
    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.

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Simple way of accessing the title is:

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

  4. The Following User Says Thank You to Schmoopy For This Useful Post:

    jimbowvu80s (11-24-2009)

  5. #4
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Thanks Schmoopy. That works perfectly.

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
  •