Javascript not executing google chrome extensioin

Javascript not executing google chrome extensioin

本文关键字:chrome extensioin google executing not Javascript      更新时间:2023-09-26

我是谷歌浏览器扩展程序的新手,我需要开发一个弹出窗口,让搜索弹出窗口中的一些文本,我遵循了本教程:http://developer.chrome.com/extensions/getstarted.html

这是弹出窗口的 html 代码.html,它在导航器中工作,但是当我加载扩展时会出现弹出窗口,但当我单击查找时,文本没有突出显示。

<script src="popup.js" type="text/javascript" > </script>
<input type="text" id="search">
<input type="button" id="button"   
onmousedown="doSearch(document.getElementById('search').value)" value="Find">
<div id="content">
<p>Here is some searchable text wsdith some lápices in it, and more lápices, and some    

对于垫子

弹出窗口.js如下:

    function doSearch(text) {
      if (window.find && window.getSelection) {
          document.designMode = "on";
          var sel = window.getSelection();
          sel.collapse(document.body, 0);
          while (window.find(text)) {
              document.getElementById("button").blur();
             document.execCommand('hiliteColor', false, 'yellow');
              sel.collapseToEnd();
          }
          document.designMode = "off";
      } else if (document.body.createTextRange) {
          var textRange = document.body.createTextRange();
          while (textRange.findText(text)) {
              textRange.execCommand("BackColor", false, "yellow");
              textRange.collapse(false);
          }
      }
  }

几件事。你不能内联你的javascript,所以你应该改为:

var input = document.getElementById('button');
input.addEventListener('mousedown', function () {
    doSearch(document.getElementById('search').value);
});

designMode命令区分大小写。更改以下行:

document.execCommand('HiliteColor', false, 'yellow');

自:

document.execCommand('hiliteColor', false, 'yellow');

虽然我不明白如果这仅适用于 Chrome 扩展程序,为什么您会进行功能检测,但您还需要将该命令更改为 backColor