Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

html - What happens if the meta tags are present in the document body?

I am working on a ASP application and the code, template and files are organized in a way that does not allow me to alter anything outside the body tag. So I am thinking about inserting the meta tags inside the body -- like this:

<!-- FEW ASP INCLUDES -->
<html>
    <head>
    <!-- FALLBACK TITLE AND DESCRIPTION -->
    <title>Default Title</title>
    <meta name="description" content="Default Description">
</head>
<body>
    <!-- SOME HTML MARKUP -->
    <div class="dynamic-content">
        <!-- InstanceBeginEditable name="dynamic-content" -->
        <!-- THIS IS WHERE I CAN WRITE ASP CODE -->
        <title><%= Page.Meta.GetTitle( yada, yada ) %></title>
        <meta name="description" content="<%= Page.Meta.GetDescription( yada, yada ) %>">
        <!-- InstanceEndEditable -->
    </div>
    <!-- SOME MORE HTML MARKUP -->
</body>
</html>

I am wondering how good it is to put meta tags inside the body of an HTML document. How does it affect:

  1. search engines
  2. browsers
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is of course invalid as per HTML4.01. META tags are only allowed within HEAD (just like, say, TITLE) so by putting it into a BODY, you're essentially creating an invalid markup.

From the cursory tests, it seems that some browsers (e.g. Firefox 3.5 and Safari 4) actually put these elements into HEAD when creating a document tree. This is not very surprising: browsers are known to tolerate and try to interpret all kinds of broken markup.

Having invalid markup is rarely a good idea. Non-standard handling by browsers might lead to various hard-to-pin rendering (and behavioral) inconsistencies. Instead of relying on browser guessing, it's best to follow a standard.

I don't know how search engines react to such tag soup, but I wouldn't risk experimenting to find out :) Perhaps they only parse HEAD tag for certain information and will skip your BODY-contained tags altogether. Or maybe they consider these to be some malicious gambling attempts and black-list pages containing such markup. Who knows.

The bottom line — avoid this whenever possible.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...