[英]Chrome Extension - How to pass variables from JS to popup.html?
I have some variables in the following JS: 我在以下JS中有一些变量:
document.addEventListener('DOMContentLoaded', function (){
document.getElementById('btn4').addEventListener('click', getbg);
});
getbg = function()
{
chrome.runtime.getBackgroundPage(
function (bg) {
var allcompanynames = bg.companynames;
alert(allcompanynames)})
}
As you can see, the variable is "allcompanynames". 如您所见,变量是“ allcompanynames”。
However, how do I pass them and show it on the popup.html page? 但是,如何传递它们并将其显示在popup.html页面上?
I have tried 我努力了
<script type="text/javascript" src="companynames.js"></script>
<p id="allcompanynames"></p>
no luck. 没运气。 What's wrong?
怎么了?
document.addEventListener('DOMContentLoaded', function (){
document.getElementById('btn4').addEventListener('click', getbg);
});
getbg = function()
{
chrome.runtime.getBackgroundPage(
function (bg) {
var allcompanynames = bg.companynames;
alert(allcompanynames)})
document.getElementById("allcompanynames").innerHTML(allcompanynames)
}
I'm guessing you should add that last line after displaying the pop up to add the content into the page. 我猜您应该在显示弹出窗口以将内容添加到页面后添加最后一行。
Write your code in this way 用这种方式编写代码
var background = chrome.extension.getBackgroundPage();
var allcompanynames = background.companynames;
alert(allcompanynames)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.