简体   繁体   English

如何将多个页面的不同元信息放在一个HTML文件中?

[英]How do I put different meta info for multiple pages in a single HTML file?

I am building a website that has multiple pages in one html file using different div elements. 我正在建立一个使用不同的div元素在一个html文件中包含多个页面的网站。 The code is similar to the code below. 该代码类似于下面的代码。 I need to have different meta descriptions and titles for each of the different pages in that one html file. 对于一个html文件中的每个不同页面,我需要具有不同的元描述和标题。 Can this be done? 能做到吗?

Here is the code: 这是代码:

<html>
<head>
<script>
function show(shown, hidden) {
  document.getElementById(shown).style.display='block';
  document.getElementById(hidden).style.display='none';
  return false;
}
</script>
</head>
<body>

  <div id="Page1">
    Content of page 1
    <a href="#" onclick="return show('Page2','Page1');">Show page 2</a>
  </div>

  <div id="Page2" style="display:none">
    Content of page 2
    <a href="#" onclick="return show('Page1','Page2');">Show page 1</a>
  </div>

</body>
</html>

I have tried putting different in each of the div elements but Facebook just chooses one of them out of the document and uses it for all of the pages. 我曾尝试在每个div元素中添加不同的内容,但Facebook只是从文档中选择其中一个,并将其用于所有页面。

You cannot use JavaScript to modify the meta data that Facebook (or most other crawlers) will index from your pages. 您无法使用JavaScript来修改Facebook(或大多数其他爬网程序)将从页面中索引的元数据。 Most crawlers do not execute JavaScript, so only that meta data present in the raw HTML will be detected. 大多数搜寻器不执行JavaScript,因此仅原始HTML中存在的元数据将被检测到。

You must modify your meta data on the server, before the HTML is sent to the client. 在将HTML发送到客户端之前,您必须在服务器上修改元数据。

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

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