如何在我的网站上使用谷歌搜索? [英] How do I use google search on my webiste?

查看:284
本文介绍了如何在我的网站上使用谷歌搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想谷歌搜索搜索我的网站。我有一个文本框来添加文本和一个提交按钮。因此,当我点击提交时,我希望它通过我的网站搜索单词。



这里是谷歌给我的代码



I want google search to search my website. I have a textbox to add text and a button to submit. So when I click submit i want it to search through my website for the words.

here is the code google gave me

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

推荐答案

添加< script>阻止< head>页面的一部分。然后写下行,而不是文本框和提交按钮:

Add the <script> block in the <head> section of your page. Then instead of your text box and submit button, write the line:
<gcse:search></gcse:search>



此元素将自动替换在运行时使用文本框和搜索按钮。以下是显示如何使用谷歌搜索的完整HTML:




This element will be automatically replaced with a text box and search button at run time. Here is the complete HTML that shows how to use google search:

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <script>
        (function () {
            var cx = '012117305473792254352:kosbw5yycts';
            var gcse = document.createElement('script');
            gcse.type = 'text/javascript';
            gcse.async = true;
            gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(gcse, s);
        })();
</script>

</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <gcse:search></gcse:search>
    </div>
    </form>
</body>
</html>


这篇关于如何在我的网站上使用谷歌搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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