JavaScript函数未加载到chrome扩展程序

时间:2016-11-19 11:40:34

标签: javascript google-chrome-extension

我有一个XMLHttpRequest,它现在在html文件中的div标签中返回一个字符串,但它不起作用。

HTML:

<html>
<head>
  <link rel="stylesheet" href="css/style.css" />
  <script type="text/javascript" src="scripts.js"></script>
</head>
  <body onload="renderXML()">
      <div id="news_1"></div>
  </body>
</html>

JavaScript:url

function renderXML() {
var xmlreq = new XMLHttpRequest();
xmlreq.open("GET",url);
xmlreq.responseType = 'json';
xmlreq.send(null);

xmlreq.onreadystatechange = function () {
  if (xmlreq.readyState === XMLHttpRequest.DONE && xmlreq.status === 200) {
    var nr = xmlreq.response;
  document.getElementById('news_1').innerHTML = nr.hash.variants[0];
      }
    }

}

的manifest.json:

{
    "name": "Extension",
    "version": "1.0",
    "description": "Extension",
    "manifest_version": 2,
    "browser_action": {
      "default_icon": "icon.png",
      "default_popup": "mypopup.html"
    },
    "content_scripts": [ {
  "matches": ["*://*/*"],
  "js": ["scripts.js"]
} ]


}

为什么这不起作用?

0 个答案:

没有答案