Accessing <title> through JavaScript

D

Don G

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
 
L

Lauri Raittila

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.
 
D

Don G

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
 
L

Lauri Raittila

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...
 
D

Don G

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.

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
 
L

Lauri Raittila

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.


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.
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.
 
N

nice.guy.nige

While the city slept, Don G ([email protected]) 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
 
D

Don G

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.
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top