12

我有一个页面,其中通过使用 JavaScript 读取一些 JSON 来动态加载一些事件。我使用Schema.org 标记div为每个事件构建一个。Event

Google 的测试工具不会读取此标记。是因为标记错误,还是因为动态加载?

其中一个的 HTML 代码Event是:

<div class="evento well" itemscope itemtype="http://schema.org/Event">
   <meta itemprop="startDate" content="2015-03-20T20:00:00.000Z">
   <meta itemprop="endDate" content="2015-01-21T20:00:00.000Z">
   <div class="dataEvento">
      <div class="dayWeekEvento">venerdì</div>
      <div class="dayNumEvento">20</div>
      <div class="monthEvento">Marzo</div>
   </div>
   <div class="datiEvento">
      <div class="oraEvento">ore 21:00</div>
      <div class="titoloEvento"><span itemprop="name">Titolo evento</span></div>
      <div class="luogoEvento" itemprop="address" itemscope="" itemtype="http://schema.org/PostalAddress"><a href="https://www.google.it/maps/place/Milano" target="_blank"><span class=" glyphicon glyphicon-map-marker" aria-hidden="true"></span> <span itemprop="addressLocality">Milano</span></a></div>
   </div>
</div>
4

3 回答 3

22

谷歌的文档只提到如果使用 JSON-LD 语法,他们可以使用动态添加的结构化数据:

此外,即使通过 Javascript 代码或嵌入的“小部件”等动态注入页面内容,Google 也可以读取 JSON-LD 数据。

这并不一定意味着他们无法在其他语法(如 Microdata 或 RDFa)的情况下阅读它,但至少他们没有记录它。

他们的测试工具没有读取它可能意味着也可能不意味着什么(可能是该工具不处理这个,但他们的内部系统可以)。但是,您的实际标记应该没有问题,因为您可以通过粘贴标记而不是输入 URL 来轻松地自己测试它。

于 2015-03-15T22:08:33.600 回答
3

If you're having trouble validating schema markup with the Google testing tool, you can create the json-ld snippet with JS, which also allows you to manipulate the data if needed like:

<script> 
    (function(){
       var data = {
            "@context": "http://www.schema.org",
            ...
        }
        var script = document.createElement('script');
        script.type = "application/ld+json";
        script.innerHTML = JSON.stringify(data);
        document.getElementsByTagName('head')[0].appendChild(script); 
    })(document);
</script>
于 2018-08-02T15:45:39.670 回答
0

这取决于它是什么类型的标记。来自谷歌

JSON-LD is supported for all Knowledge Graph features, sitelink search boxes, Event Rich Snippets, and Recipe Rich Snippets; Google recommends the use of JSON-LD for those features. For the remaining Rich Snippets types and breadcrumbs, Google recommends the use of microdata or RDFa.

It should work but I know people have reported problems with the testing tool.

于 2016-04-27T19:18:01.427 回答