Advanced Search

Results 1 to 9 of 9

Thread: <title></title> in header

  1. #1
    Join Date
    Sep 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default <title></title> in header

    This may sound like a stupid question but I'm sure it has a simple answer.

    I have one 'header' asp file that I virtually 'include' in all of my documents. In this header I have a title tag <title>My Website Homepage</title>, for instance. A single file 'footer' is also then virtually 'included' within the documents to close the code out.

    How can I change this <title></title> in every page to something different <title>My Website - Page 1</title>, for instance???

    Can't think of how to do it and I'm sure there is an easy answer. Does the <title> have to be in the header of ALL documents?

    Any help would be greatly appreciated.

    Cheers.

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    The default location for the title tag is within the <head> tag. Now you have a header.asp file that you virtually include in all your pages, right?

    Either you can do something like the following inside your header.asp file

    Code:
    Response.Write "<script type='text/javascript'> window.onload = function() {document.title = 'The Title You Want'; } </script>"
    Make sure that you don't have any other window.onload event triggering in any of your pages. If you have then you must handle it appropriately.

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter View Post
    Code:
    Response.Write "<script type='text/javascript'> window.onload = function() {document.title = 'The Title You Want'; } </script>"
    Ick. I'm not familiar with the inclusion process in ASP, but would it not be possible to define a variable in the document that is including and use that variable in the document to be included?

    In PHP, one could write:

    PHP Code:
    <?php
    $documentTitle 
    'foo';

    include(
    '/header.php');
    ?>
      </head>

      <body>
        <!-- ... -->
      </body>
    </html>
    where header.php contained:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    <html>
      <head>
        <title><?php echo $documentTitle?> ߞ My Site</title>

        <!-- ... -->
    Is there not something analogous to that with ASP?
    Mike

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    No, I've actually tried the above method, mwinter, and for some reason it does not work. This is because the included file is not affected by what it's being included in.

    The best, and easiest, way to do this is with the javascript method posted by codeexploiter. Now, you have to understand, though, that this method does not actually change the real title, but just its display. So Google still sees My Website, and not My Website - Page 1. But if the reason is for the viewer to see a more detailed title, then this is the way to go.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I'd say to have the included file define a function, then, which takes a title as parameter and outputs the header with the correct title. You can then call that from your main page after including the header file.

    If this won't work and there's truly no better way to do it than Javascript, get a real server-side language
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Hahahaha

    get a real server-side language
    Amen.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  7. #7
    Join Date
    Jan 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    no one says the virtual include has to be the first thing on the page.
    since the header's tag structure is likely to be doctype->html->head->title and then more header code,
    you can put just that first bit at the top of each page (with the relevant title) and then continue with the virtual include of the header.

  8. #8
    Join Date
    Dec 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Try this:

    --------- In each page at the top before include statement -----------
    <%
    Dim pageTitle
    pageTitle = "## Your page title here! ##"
    %>
    -----------------------------------
    --------- In Server Include File ----
    <title><%= pageTitle %></title>
    -----------------------------------

    Upgrade to ASP.NET, it's is easier!

  9. #9
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by alexjewell View Post
    Hahahaha



    Amen.
    Quote Originally Posted by protoskore View Post
    no one says the virtual include has to be the first thing on the page.
    since the header's tag structure is likely to be doctype->html->head->title and then more header code,
    you can put just that first bit at the top of each page (with the relevant title) and then continue with the virtual include of the header.
    Quote Originally Posted by kooshal View Post
    Try this:

    --------- In each page at the top before include statement -----------
    <%
    Dim pageTitle
    pageTitle = "## Your page title here! ##"
    %>
    -----------------------------------
    --------- In Server Include File ----
    <title><%= pageTitle %></title>
    -----------------------------------

    Upgrade to ASP.NET, it's is easier!


    this topic is nearly 6months idle. look at the time before you post a reply

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
  •