Jump to content

Changing Or Adding A Title


just2comment
 Share

Recommended Posts

The code below doesn't show the assigned title in OP, but it does in FF and IE, is it an OP W3C compliance problem?

<html><!--  <head>	<title>Web example</title>  </head>-->  <body>	<h1>Hi</h1>	<script type="text/javascript">	  document.title = "Title changed";	</script>  </body></html>

If the head section is uncommented (does exist such a word?) all browsers show "Title changed" as title.------------------------------------------------Browser identificationOpera/9.80 (Windows NT 6.0; U; en) Presto/2.2.15 Version/10.01------------------------------------------------

Edited by just2comment
Link to comment
Share on other sites

The code below doesn't show the assigned title in OP, but it does in FF and IE, is it an OP W3C compliance problem?
<html><!--  <head>	<title>Web example</title>  </head>-->  <body>	<h1>Hi</h1>	<script type="text/javascript">	  document.title = "Title changed";	</script>  </body></html>

If the head section is uncommented (does exist such a word?) all browsers show "Title changed" as title.------------------------------------------------Browser identificationOpera/9.80 (Windows NT 6.0; U; en) Presto/2.2.15 Version/10.01------------------------------------------------

<!-- should be inside the script tags. And the script tags should be inside the head tags.
Link to comment
Share on other sites

<!-- should be inside the script tags.
Well, in fact "<!--" is for beginning an HTML comment, and script comments have different syntax.
And the script tags should be inside the head tags.
Not necessarily, script tags can be in the body section too, even when it is not recommended in general, I've used this way just because it's a short example.Finally, if you put the JavaScript code in the head section it doesn't work either.
Link to comment
Share on other sites

The <title> element is required according to the HTML DTD, so if you don't put it each browser can choose whether to create the DOM element for it or not. Apparently, Opera doesn't generate one.Other elements, such as <head> and <body> are implied, as the specification says, so browsers have to create them even if it's not in the code of the page.All I can say is that you should make sure you create a <title> element in every single one of your pages.

Link to comment
Share on other sites

A long time ago, when many browsers did not understand scripts, it was common to put comment tags inside a script so that the HTML parser would not get confused. It is no longer necessary, but you still see this sometimes in older documents:

<script type="text/javascript"><!--// code goes here//--></script>

This may have been behind the suggestion to put the comment tags inside the script. (I really don't know.)Scripts are certainly permitted in the body section, but good developers usually place them in the head unless there is a very, very good reason not to.What I am not clear about is if Opera is changing your title correctly when the head and title tags are not commented. In other words, does your code fail when everything else is normal?

Edited by Deirdre's Dad
Link to comment
Share on other sites

This may have been what Ingolme was thinking when he said to put the comment tags inside the script.
I think you're referring to ApocalypseX, I'd never suggest putting comments in script tags.
Link to comment
Share on other sites

Thank you all, very much. In the original post I was trying to say that this

<html>  <head>	<title>Web example</title>  </head>  <body>	<h1>Hi</h1>	<script type="text/javascript">	  document.title = "Title changed";	</script>  </body></html>

works as expected in IE, OP, and FF, showing as title "Title changed" after executing the JavaScript code, but this

<html><!--  <head>	<title>Web example</title>  </head>-->  <body>	<h1>Hi</h1>	<script type="text/javascript">	  document.title = "Title changed";	</script>  </body></html>

doesn't work as (I) expected in OP, since the title is not assigned as "Title changed". I didn't know about the implied and required elements for HTML documents as explained in post #4. I'll search for those elements in w3c specification/definitions.Thanks again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...