【问题标题】:How to give Chrome Extension ability to Search a certain site如何让 Chrome 扩展程序能够搜索某个站点
【发布时间】:2015-05-13 00:03:58
【问题描述】:

我正在尝试制作一个 Chrome 浏览器扩展程序,让您可以搜索我的网站。网站上的搜索框有效。但是当我将相同的 HTML 代码添加到我的扩展文件中时,它就不起作用了。这是我的搜索框的代码:

<form class="text-center" id="searchGuides" action="https://www.arcanumgaming.com/game" method="GET">
     <input type="hidden" name="a" value="search" />
     <input type="hidden" name="g" value="grand-theft-auto-v" />
     <div >
            <input type="text" name="searchVal" class="searchField" placeholder="Search Game Content"  />
     </div>
     <div >
            <a href="#" class="searchBtn" onclick="document.getElementById('searchGuides').submit();">Search Content</a>
     </div>
</form>

【问题讨论】:

    标签: google-chrome browser google-chrome-extension browser-addons


    【解决方案1】:

    内联 JavaScript 将不会被执行。此限制禁止内联块和内联事件处理程序(例如&lt;button onclick="..."&gt;)。

    你必须这样做:

    文件.html

    <script src="file.js"></script>
    ...
    <form class="text-center" id="searchGuides" action="https://www.arcanumgaming.com/game" method="GET">
         <input type="hidden" name="a" value="search" />
         <input type="hidden" name="g" value="grand-theft-auto-v" />
         <div >
                <input type="text" name="searchVal" class="searchField" placeholder="Search Game Content"  />
         </div>
         <div >
                <a href="#" class="searchBtn">Search Content</a>
         </div>
    </form>
    

    文件.js

    function clickHandler() {
      document.getElementById('searchGuides').submit();
    }
    document.addEventListener('DOMContentLoaded', function () {
      document.querySelector('a').addEventListener('click', clickHandler);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 2018-05-27
      • 2017-06-17
      • 2011-08-02
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      相关资源
      最近更新 更多