Javascript Chrome背景页问题
我正在构建一个Chrome扩展,我是这样设计的: 我有一个:Javascript Chrome背景页问题,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,我正在构建一个Chrome扩展,我是这样设计的: 我有一个: popup.html(浏览操作弹出窗口) popup.js(包含在popup.html中) background.html(后台脚本) background.js(包含在background.js中) 如何工作:后台页面(以及相关的js)执行并创建一个HTML表 单击浏览器操作弹出图标后,我从背景页面DOM检索该表(通过getBackgroundPage),并将其附加到popup.html中 发生的情况:我第一次点击按钮时,任何东
- popup.html(浏览操作弹出窗口)李>
- popup.js(包含在popup.html中)李>
- background.html(后台脚本)李>
- background.js(包含在background.js中)李>
// reference to the background page window
var w = chrome.extension.getBackgroundPage();
console.log(w);
// the background page week table
var newWeek = w.document.getElementById("week");
console.log(newWeek);
// the popup week table
var oldWeek = document.getElementById("week");
// replace popup table with background table (first time it works, second time newWeek is null)
oldWeek.parentNode.replaceChild(newWeek,oldWeek);
实际上,您正在将表从后台页面DOM树移动到弹出式DOM树。当弹出窗口关闭时,表格将丢失。您可以尝试添加,以获得表的副本:
var newWeek = w.document.getElementById("week").cloneNode(true);
可能您在popup.js中的代码正在破坏表。请在你的问题中添加相关代码。我会尽快编辑帖子,但没有代码破坏背景表。我不敢相信:我以为我是在复制,不是在移动!非常感谢!:-)