Forum Moderators: open

Message Too Old, No Replies

Changing page title dynamically!

         

Etar

1:09 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



Hi,

I wanted to change the title of my web pages so I did like this:

<SCRIPT>
top.document.title.value = '';
top.document.title = top.curCatName + " Templates";
</SCRIPT>

it is working fine and the title on the title par for the Internet explorer changed successfully but if I open the page as HTML code the title in the title tag (<title>< /title >) do not change, so how can I let the tile in the title tag to change by using java script?

MatthewHSE

1:20 pm on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't do it with JavaScript. Besides which, search engines may not get the title correctly that way, and the title is the most important aspect of a page in the eyes of the SE's.

Have you thought of trying some server-side method?

Lord Majestic

1:49 pm on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HTML source does not change title because it is designed to show source code, not execute JavaScript in it.

Technically possible - one might have default <title> for search engines and then change it dynamically for those browsers that support it.

I am struggling to find good reason for that however.

Etar

2:50 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



>search engines may not get the title correctly that way

For that reason I want to change the title text in the title tag.

Etar

2:57 pm on Aug 26, 2004 (gmt 0)

10+ Year Member



But I do not understand why I can not change it in the same html code! what about DOM object?

Lord Majestic

3:03 pm on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But I do not understand why I can not change it in the same html code!

You mean you expected to see title changed after page was loaded in place of <title> tags in source preview? If that, then its not happening because its source view, ie original source of the page, not current run-time version.

The only way to get it in source is to generate it server side (once).

kaled

2:31 am on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be aware that some browsers may refuse to assign the title. I played around with this a few years ago and Netscape failed then so Mozilla etc. may fail now.

Kaled.