简体   繁体   English

检查页面源代码时,HTML标头出现两次

[英]HTML header appears twice when check page source code

I have a strange issue with my work. 我的工作有一个奇怪的问题。 While I do test on my local host of my web project while doing page source check i am getting following: 当我在做页面源代码检查的同时在我的Web项目的本地主机上进行测试时,我得到以下提示:

   <!DOCTYPE    html>   
  <html>    
  <head>    
            <meta   charset="UTF-8">    
            <script src="Scripts/jquery-1.11.0.js"></script>    
  </head>   
  <body>    
 <!DOCTYPE html>
   <html>
 <head>   
  <title></title>
  <link rel="stylesheet" type="text/css" href="/Content/style.css" />
</head>
  <body>

Doctype seems to appear twice. Doctype似乎出现了两次。 But in my actual code it is only 但是在我的实际代码中

     <!DOCTYPE html>
    <html>
 <head>   
   <title></title>
   <link rel="stylesheet" type="text/css" href="/Content/style.css" />
   </head>
   <body>

Any ideas why could it happen? 任何想法为什么会发生? I have created project in Visual Studio. 我已经在Visual Studio中创建了项目。 Thanks 谢谢

I had a similar issue which may or may not apply to your case. 我有一个类似的问题,可能不适用于您的情况。

In my case, I had index.html which started like this.. 就我而言,我的index.html就是这样开始的。

<!--#include virtual="/common/incl/html.incl" -->
<head>

In html.incl I defined the doctype amongst other things.. 在html.incl中,我定义了doctype等。

<!doctype html>
<!--[if lt IE 8]><html class="no-js ie lt-ie9 lt-ie8" lang="en" itemscope itemtype="http://schema.org/" xmlns:fb="http://ogp.me/ns/fb#"><![endif]-->
<!--[if IE 8]><html class="no-js ie ie8 lt-ie9" lang="en" itemscope itemtype="http://schema.org/" xmlns:fb="http://ogp.me/ns/fb#"><![endif]-->
<!--[if IE 9]><html class="no-js ie ie9" lang="en" itemscope itemtype="http://schema.org/" xmlns:fb="http://ogp.me/ns/fb#"><![endif]-->
<!--[if gt IE 9]><!--><html class="no-js" lang="en" itemscope itemtype="http://schema.org/" xmlns:fb="http://ogp.me/ns/fb#"><!--<![endif]-->

But when the source was generated it was generating a duplicate doctype appearing after the conditional comments. 但是,在生成源代码时,它会生成一个重复的doctype,出现在条件注释之后。

When I removed the doctype declaration from the .incl file and instead declared it in the .html file BEFORE the include then it resolved the issue. 当我从.incl文件中删除doctype声明,而在include之前在.html文件中声明它时,它解决了该问题。 .html documents are required to start with a document type declaration so since I was not initially defining one in the .html file, but rather in the .incl file, something else in my workflow was adding it for me. .html文档必须以文档类型声明开头,因此,由于我最初不是在.html文件中定义一个,而是在.incl文件中定义,因此我的工作流程中有其他内容要为我添加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM