将Google自定义搜索添加到AMP网站 [英] Adding Google Custom Search to AMP site

查看:85
本文介绍了将Google自定义搜索添加到AMP网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的Google自定义搜索引擎(GCSE)代码:

I have my Google Custom Search Engine (GCSE) code:

<script>
  (function() {
    var cx = '008589157460623253837:mhsjluzrngo';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>

但是,我的加速移动页面(AMP)网站不允许我向其中添加JavaScript,并且看不到任何允许将GCSE嵌入AMP网站的AMP组件.

However my Accelerated Mobile Pages (AMP) site does not allow me to add JavaScript to it, and I don't see any AMP components that allow for embedding GCSE into an AMP site.

如何在不违反AMP要求的情况下在自己的网站上获得GCSE?

How can I get GCSE on my site without breaking AMP compliance?

谢谢

推荐答案

您可以尝试将代码放在单独的页面中,然后通过amp-iframe组件将该页面包括在AMP中.您还必须遵守此处描述的约束: https://www. ampproject.org/docs/reference/components/amp-iframe

You can try putting that code in a separate page then including that page in your AMP via the amp-iframe component. You will also have to abide by the constraints described here: https://www.ampproject.org/docs/reference/components/amp-iframe

这篇关于将Google自定义搜索添加到AMP网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆