browser_action 实例
//manifest.json
"browser_action": {
"default_popup": "popup.html",
"default_icon": "images/icon-16.png"
},
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="scripts/jquery.js"></script>
<script src="scripts/popup.js"> </script>
</head>
<body style="width:300px ;height:300px">
<h1>Hello, Chrome</h1>
<input type="text" id="input" value="0">
<button id="btn">+1</button>
</body>
</html>
在browser_action 不能直接写js代码要 引入方式
无法使用cdn地址的jquery
var count = 0;
$(function(){
$('#input').val(count);
$('#btn').click(function(){
console.log('1')
count = count+1;
$('#input').val(count);
});
})
console.log('') 的查看
![](https://img.haomeiwen.com/i1351616/3ce463397792a97b.png)
//未定义default_popup时在background代码中添加监听
chrome.browserAction.onClicked.addListener(
function(tab) { //tab对象表示当前(用户点击browser action的时候)处于活动状态的tab
console.log('onClicked', tab);
});
//active: true, audible: false, autoDiscardable: true, discarded: false, favIconUrl: "", …
![](https://img.haomeiwen.com/i1351616/f960ec6ee397c3f3.png)
![](https://img.haomeiwen.com/i1351616/50bbb96df81c87fe.png)
网友评论