不能使用javascript更改newtab内容?

不能使用javascript更改newtab内容?,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,我想用javascript修改newtab的内容。在我的manifest.json中 "chrome_url_overrides": { "newtab": "index.html" } 然后在我的index.html中 <script src="jquery.js"></script> <script src="script.js"></script> <body> <h1>hello world<

我想用javascript修改newtab的内容。在我的manifest.json中

"chrome_url_overrides": {
      "newtab": "index.html"
   }
然后在我的index.html中

<script src="jquery.js"></script>
<script src="script.js"></script>
<body>
<h1>hello world</h1>
</body>

你好,世界

然后在我的script.js中执行
$('h1').remove()
未触发任何操作。为什么?当我尝试执行
console.log($)
时,它起了作用。

当Chrome将
标记插入DOM树时,您的代码就会运行

到那时,
还没有出现

有两种解决办法;一种方法是简单地将
标记移动到所指节点下方

另一个更好的解决方案是使用一个事件,该事件表示“好的,DOM树已经完成,您现在可以处理节点了”。使用jQuery,它将是:

或者缩短,

$(function() {
  /* your code here */
});
$(function() {
  /* your code here */
});