我目前正在为阅读困难创建chrome扩展程序,并试图将扩展程序的弹出窗口中的按钮链接链接为更改页面的字体大小,作为第一步,但是我无法使其正常工作。问题是按下弹出窗口中的按钮后什么也没有发生。
以下是弹出窗口的html:
<!DOCTYPE html>
<html>
<head>
<style>
button {
height: 30px;
width: 30px;
outline: none;
}
</style>
</head>
<body>
<button id="changeFont"></button>
<script src="popup.js"></script>
</body>
</html>
这是弹出HTML的源文件:
let changeFont = document.getElementById('changeFont');
changeFont.onclick = function(element) {
chrome.tabs.executeScript({
code:
'var elements = document.getElementsByTagName('*');'+
'for (var i = 0; i < elements.length; i++) {' +
'var element = elements[i];' +
'element.style.fontSize = "50px";'+
'}'
});
};
最后,这是清单文件:
{
"manifest_version": 2,
"name": "Dyslexipro",
"description": "dyslexia aid ",
"version": "1.0",
"permissions": ["activeTab",
"tabs","declarativeContent","storage"],
"browser_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
}
},
"icons": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"background": {
"scripts": ["content.js","popup.js"],
"persistent": true
}
}