使用Google脚本将页面(链接的)放置在边栏中

时间:2018-06-22 12:17:57

标签: html5 google-apps-script google-docs

您好,我想知道是否有可能,因为我已经完成了google脚本教程中的边栏示例,所以当我们单击用Google搜索enter image description here打开的标签时,我已经链接到google网站。 enter image description here 我的问题是,可以单击并在侧边栏中搜索Google页面,然后在此处进行搜索吗?谢谢。

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Click <a href="https://www.google.com/" target="_blank">here</a> for a google search
    <input type="button" value="Ferme"
        onclick="google.script.host.close()" />
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

此脚本将从输入框中获取搜索词组,并打开一个包含结果的新标签:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">

    <script>
      function doSearch() {
        var searchFor = document.getElementById("txtSearchFor").value;

        window.open("https://www.google.com/search?q=" + searchFor);
      }
    </script>
  </head>
  <body>
    <H1>Sidebar</H1>

    <input type="text" id="txtSearchFor"/>
    <input type="button" value="Search" id="btnSearch" onclick="doSearch()"/>

  </body>
</html>

如果您想对结果进行实际处理,那么应该考虑使用google custom search api,它会涉及更多的内容。