Я работаю в расширении Google Chrome.У меня в popup.js есть функция, которая заполняет таблицу update_table .Я хочу вызвать эту функцию из моего background.js, который отправляет важные данные.Проблема в том, что update_table на background.js не определен, и если я копирую код в этот файл, не обновляю таблицу на popup.html.
popup.js
function update_table(content, morecontent){
if (!document.getElementsByTagName) return;
tabBody=document.getElementsByTagName("tbody").item(0);
row=document.createElement("tr");
cell1 = document.createElement("td");
cell2 = document.createElement("td");
textnode1=document.createTextNode(content);
textnode2=document.createTextNode(morecontent);
<!-- ... -->
}
popup.html
<!doctype html>
<html>
<head>
<title>Popup Page</title>
<script src="./popup.js" type="text/javascript"></script>
</head>
<body>
<table border='1' id='mytable'>
<tbody>
<tr><td>22</td><td>333</td></tr>
<tr><td>22</td><td>333</td></tr>
</tbody>
</table>
</body>
</html>
background.js
chrome.webRequest.onCompleted.addListener(
function(request) {
update_table(request.type, request.url);
},
{urls: ["*://*/*"]},
["responseHeaders"]
);
background.html
<!doctype html>
<html>
<head>
<title>Background Page</title>
<script src="./background.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>