Javascript not executing google chrome extensioin
Javascript not executing google chrome extensioin
我是谷歌浏览器扩展程序的新手,我需要开发一个弹出窗口,让搜索弹出窗口中的一些文本,我遵循了本教程: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
。
相关文章:
- Chrome WebKitGetUserMedia
- JQueryhide()不适用于Mozzilla,但适用于Chrome
- 在chrome.tabs.onCreated之后加载HTML页面
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- chrome扩展更改主机/域警告
- Chrome开发工具(如何知道我在调用哪个javascript对象)
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- Google/html5语音识别JavaScript SDK Chrome网络工具包SpeechRecognition
- 激活chrome上的chrome.notifications对象
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- JS可以在Chrome中工作,但不能在Firefox中工作
- Chrome加载旧版本的Javascript文件
- 试图阻止Chrome通过扩展关闭
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 是什么让一个“;Uncaught RangeError:超过了最大调用堆栈大小“;错误(Chrome,在其他浏览器中显示
- Javascript not executing google chrome extensioin