简体   繁体   中英

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. 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. 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.

You cannot use JavaScript to modify the meta data that Facebook (or most other crawlers) will index from your pages. Most crawlers do not execute JavaScript, so only that meta data present in the raw HTML will be detected.

You must modify your meta data on the server, before the HTML is sent to the client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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