Accessing <title> through JavaScript

Discussion in 'HTML' started by Don G, Feb 16, 2005.

  1. Don G

    Don G Guest

    Is is possible to access the <title> element using JavaScript? In my
    HTML, I have:

    <title id="bob"></title>

    and in my JavaScript I have:

    bobtext = "test";

    document.getElementById('bob').innerHTML = bobtext;

    I am using similar code elsewhere to change a caption, but it doesn't
    work here. So, is it just not allowed to modify <title> in this way, or
    am I doing something wrong?

    Thanks,

    Don
     
    Don G, Feb 16, 2005
    #1
    1. Advertising

  2. in alt.html, Don G wrote:
    > Is is possible to access the <title> element using JavaScript? In my
    > HTML, I have:
    >
    > <title id="bob"></title>


    VEry bad idea. What if JS is disabled?

    > and in my JavaScript I have:
    >
    > bobtext = "test";
    >
    > document.getElementById('bob').innerHTML = bobtext;
    >
    > I am using similar code elsewhere to change a caption, but it doesn't
    > work here. So, is it just not allowed to modify <title> in this way, or
    > am I doing something wrong?


    Title can't have id in HTML. To tell more, tell your
    URL
    Browsers you used to test
    and post to javascript group. They might actually know how to do it.

    --
    Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
    Utrecht, NL.
     
    Lauri Raittila, Feb 16, 2005
    #2
    1. Advertising

  3. Don G

    Guest

    use the following:

    myVar = "MyTitle"
    document.title= myVar
     
    , Feb 16, 2005
    #3
  4. Don G

    Don G Guest

    > VEry bad idea. What if JS is disabled?

    Well, then, my site would be pretty useless anyway. It's a collection
    of picture galleries that use JavaScript to change the picture. If
    JavaScript is disable, no pictures.

    I don't suppose anyone has an idea of how do this without JS. I might
    be able to do it with a CSS rollover, but I've heard that doesn't work
    very well in IE. I'm also lazy, so I don't want to have to do a ton of
    coding to put more pictures up.

    Thanks for the advice,

    Don
     
    Don G, Feb 16, 2005
    #4
  5. in alt.html, Don G wrote:
    > > VEry bad idea. What if JS is disabled?

    >
    > Well, then, my site would be pretty useless anyway. It's a collection
    > of picture galleries that use JavaScript to change the picture. If
    > JavaScript is disable, no pictures.


    So, it is not bad idea, because you have already done much bigger
    mistake...

    > I don't suppose anyone has an idea of how do this without JS.


    http://www.porjes.com/butterflies/index.php?butterfly=01

    > I might be able to do it with a CSS rollover, but I've heard that doesn't
    > work very well in IE.


    The problem is that you started wrong end. First make things work whitout
    JS, then you may add some.

    > I'm also lazy, so I don't want to have to do a ton of
    > coding to put more pictures up.


    Then do everything automagically. There is image gallery software
    everywhere...

    --
    Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
    Utrecht, NL.
     
    Lauri Raittila, Feb 16, 2005
    #5
  6. Don G

    Don G Guest

    > So, it is not bad idea, because you have already done much bigger
    > mistake...


    Well, maybe so. I made my mistake our of ignorance. I didn't really
    want to do it with JS, but I didn't know of another way.

    > http://www.porjes.com/butterflies/index.php?butterfly=01


    Excellent page. Now I just need to figure out how it is done.

    > The problem is that you started wrong end. First make things work whitout
    > JS, then you may add some.


    How should I have started?

    I guess I don't understand the purpose of JS. If you can do something
    without JS, why would you add it?

    > Then do everything automagically. There is image gallery software
    > everywhere...


    Again, ignorance. I didn't know that such software was available. Are
    these programs flexible enough that you still have full control over
    what the page will look like?

    Thanks for your help,

    Don
     
    Don G, Feb 17, 2005
    #6
  7. in alt.html, Don G wrote:
    > > So, it is not bad idea, because you have already done much bigger
    > > mistake...

    >
    > Well, maybe so. I made my mistake our of ignorance. I didn't really
    > want to do it with JS, but I didn't know of another way.
    >
    > > http://www.porjes.com/butterflies/index.php?butterfly=01

    >
    > Excellent page.


    Too bad that the ultimate brucie is not around anymore. I hope he will be
    back sometime

    > Now I just need to figure out how it is done.


    There is source code. Uses PHP.

    > How should I have started?


    Deciding what processing to use before your HTML leaves your server.

    > I guess I don't understand the purpose of JS. If you can do something
    > without JS, why would you add it?


    Because you can do things with it that
    a) make things easier/faster for those that have it
    b) to do stuff that is not possible whiout.

    And yes, with these criters, most JS around is bad usage.

    > > Then do everything automagically. There is image gallery software
    > > everywhere...

    >
    > Again, ignorance. I didn't know that such software was available. Are
    > these programs flexible enough that you still have full control over
    > what the page will look like?


    Some are. I have used JAlbum. The default templates are horrible, like in
    most image gallery software.

    --
    Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
    Utrecht, NL.
     
    Lauri Raittila, Feb 17, 2005
    #7
  8. While the city slept, Don G () feverishly typed...

    > Is is possible to access the <title> element using JavaScript?

    [...]

    http://www.nigenet.org.uk/bits-n-bobs/changeTitle/

    This is an example I knocked up a while ago for someone who wanted to change
    the parent title in a frameset, which you could adapt to your needs. Note
    that it won't work in NN4.x as that browser treats the title as read-only,
    and -- of course -- it won't work without javascript! You may also want to
    rethink what you are doing anyway as others have said. For a javascript
    image gallery which also works without javascript you may want to look at
    http://www.nigenet.org.uk/stuff/thumbtastic/ which uses PHP to "reload" the
    page with the chosen picture if javascript is not available, otherwise it
    uses javascript to change the main image and (attempt to) change the alt
    text.

    Hope that helps.

    Cheers,
    Nige

    --
    Nigel Moss
    http://www.nigenet.org.uk
    Mail address not valid. , take the DOG. out!
    In the land of the blind, the one-eyed man is very, very busy!
     
    nice.guy.nige, Feb 17, 2005
    #8
  9. Don G

    Don G Guest

    >>Now I just need to figure out how it is done.
    >
    > There is source code. Uses PHP.


    Ok, I guess I need to learn how to use PHP.

    >>How should I have started?

    >
    > Deciding what processing to use before your HTML leaves your server.


    Well, when I started this, I didn't have the option for server
    preprocessing. Now I do, so I'll rework it.

    > Because you can do things with it that
    > a) make things easier/faster for those that have it
    > b) to do stuff that is not possible whiout.


    Ok, so I may still be able to use what I have, but I will need to work
    out a PHP option for those who don't use JS.

    > Some are. I have used JAlbum. The default templates are horrible, like in
    > most image gallery software.


    Thanks, I'll take a look t JAlbum.

    Don
     
    Don G, Feb 17, 2005
    #9
  10. Don G

    Toby Inkster Guest

    Toby Inkster, Feb 17, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    1
    Views:
    465
    Steve C. Orr, MCSD
    Aug 10, 2003
  2. Replies:
    0
    Views:
    540
  3. Replies:
    1
    Views:
    557
    David
    Apr 24, 2007
  4. soonic
    Replies:
    11
    Views:
    1,783
    soonic
    Jul 27, 2011
  5. Russell
    Replies:
    2
    Views:
    290
    Russell
    Sep 13, 2004
Loading...

Share This Page