views:

538

answers:

4

Hi, I am using DreamWeaver to code xHtml docs. in the program the code is valid but when I upload it in the inspect element I see double <head> tags and when I right-click to see the source file it seems o.k.

Is it because I'm using dreamweaver? what can be wrong? the first error is : "Extra <html> encountered. Migrating attributes back to the original <html> element and ignoring the tag." - in line 3

The code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="the content of my doc" />
<meta name="description" content="this is an example document" />
<link rel="alternate" type="application/rss+xml" title="rss feeds" href="linkto/xml/feeds.xml" />
<!-- scripts -->
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
<title>The Title</title>
</head>
<body>
<!-- content -->
</body>
</html>

Thank you very much.

A: 

You should have a title element what you write between the <title></title> tags will been displayed in top bar of your browser

ShallowHeart
Sorry, I meant it is valid in Dreamweaver. now I tested it trough validator.w3.org and it doesn't report about double head tags.by checking it trough the Safari developer I see double head tags
Sophia Gavish
@Sophia: can you post (a link to) your source code? That makes it a lot easier to see what could be wrong.
Marcel Korpel
http://www.tsuriellaw.com
Sophia Gavish
+1  A: 

No problem in Chromium 5.0.307.9 (Developer Build 39052) under Linux. I can't test it in Safari now.

EDIT: Proposed test case had nothing to do with this problem, neither could see any extra <head> tags. However, I looked at the Developer Tools of Safari and Chrome under Windows and Firebug in Firefox and all three rendered the DOM incorrectly. Just have a look at this picture and see that the first <link> tag has jumped into the body.

This problem also has nothing to do with Javascript because when turning off Javascript the result is the same, even more clear when comparing with the source code. Strange I didn't notice this under Linux.

The Developer Tools of the WebKit browsers give an even clearer picture (also notice the jQuery error message). I suspect the Unicode Byte-Order Mark (BOM) at the beginning of the file causing the problem: as you can see the BOM is moved to the <body> of the document, perhaps dragging several elements in the <head> with it. But also the unclosed <link> elements, as shown by the W3C validator, might give some issues, although browsers usually handle this without any problems. First get rid of the BOM in your file and see if the problem persists.

And I see another error: those tags beginning with <meta ... are called meta tags, not "meat tags". ;-)

Marcel Korpel
I think the problem is with the Twitter widget. I see some extra code in the head (with closing tag) and that is what makes the problem.I think I should not use twitter widget and make my own code.
Sophia Gavish
@Sophia: That could be the case, as the validator doesn't process Javascript. Is the Twitter widget put in its own `iframe`?
Marcel Korpel
no, I just place the script in it's own div. I see the double head tags in the Safari developer tool, and I am sure that the extra code is from the twitter widget. I think that it is somehow added a closing tag to the head. it added extra scripts and links to css style-sheets to the head (I mean it added the code when it's online).
Sophia Gavish
@Sophia: Yes, I see, I just put that script in jsbeautifier.org and it puts something in the head three times. I don't get this problem in Chromium, so I will test your page in Safari under Windows later this evening. In the mean time, look at http://validator.w3.org/check?uri=http://www.tsuriellaw.com (nothing really serious there, but those errors could cause some unexpected problems, especially the Byte-Order Mark. Also, note "document type does not allow element "script" here; assuming missing "li" start-tag").
Marcel Korpel
I'll take a look at it, thank you very much.
Sophia Gavish
I'm tried to get rid from the BOM in my doc. since I'm using Dreamweaver I change the preferences not to use the BOM. I even made a new file and copy-paste the content but it still appears with the BOM. maybe when I copy the older content to the new file it also copy the BOM? I google about how to get rid from the BOM in Dreamweaver and I think that the changes can made for new files. Should I re-write the file in this case?
Sophia Gavish
@Sophia: I'm sorry, I really don't know Dreamweaver and I have no access to it, so I can't figure this out for you. The only thing I can recommend is: use a nice text editor (good ones support syntax highlighting and the like) and delete the BOM manually. I imagine Dreamweaver includes an option to view and edit the HTML source as well.
Marcel Korpel
I'm using Dreamweaver in code mode, Thank you very much you helped mw a lot.
Sophia Gavish
A: 

Just make sure your

</head>

tag has the slash in the actual file you're working on. That's an easy typo.

D_N
A: 

To remove BOM from your document, you can use this php function:

function removeBOM($str=""){
    if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
            $str=substr($str, 3);
    }
    return $str;}
Žan Grad