1

我正在努力创建一个 Google Chrome 扩展程序——在这个扩展程序中,有一个使用 Accordion 的弹出页面——通过 Jquery UI。

现在,我已经在 manifest.json 中正确定义了 popup.html 文件,并在 popup.html 文件中添加了 Jquery UI 的“start”主题的代码。

但是,当我单击工具栏上应该显示弹出窗口的按钮时,手风琴的所有部分都显示为打开状态——而手风琴根本没有显示——我只能看到各个部分的纯文本手风琴。

下面给出的是我的 manifest.json 的代码——

{
  "name": "Test",
  "version": "1.0",
  "manifest_version": 2,
 "content_scripts": [
     {
       "matches": ["<all_urls>"],
       "js": ["jquery-1.7.2-full.js", "basicjs.js"]
     }
  ],
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup":   "popup.html"
  } ,
  "permissions": [
      "http://*/", "https://*/"
  ],
  "background": {
      "scripts": ["background.js"]
  },
  "browser_action": {
      "default_icon": "images/anya_bl_32x32x32.png", // optional
      "default_title": "Test",      // optional; shown in tooltip
      "default_popup": "popup.html"        // optional
 }
}

此外,下面给出的是我的 popup.html 文件的一部分代码——

<html>
<head>
<title> Anya Services Data Crawler Automated Data Retrieval App</title>
<style>
/*!
 * jQuery UI CSS Framework 1.8.21
 *  Below this is the entire code for the start theme's css file....
 .................................
</style>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
  <script type="text/javascript" src="jquery-ui-1.8.21.custom.min.js"></script>
   <script>
        $(function() {
    $( "#accordion" ).accordion({
        collapsible: true
    });
});
</script>
 </head>

 <body>

<div id="accordion">
<h3><a href="#">Section 1</a></h3>
<div>
    <p>Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p>
</div>
<h3><a href="#">Section 2</a></h3>
<div>
    <p>Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna. </p>
</div>
<h3><a href="#">Section 3</a></h3>
<div>
    <p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis. Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui. </p>
    <ul>
        <li>List item one</li>
        <li>List item two</li>
        <li>List item three</li>
    </ul>
</div>
<h3><a href="#">Section 4</a></h3>
<div>
    <p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia mauris vel est. </p><p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </p>
</div>
</div>


</body>
</html>

我在这里做错了什么?如何解决此错误?

4

1 回答 1

4

"manifest_version": 2指定时,将设置默认的内容安全策略限制。后果之一是不评估内联 JavaScript。

无法启用内联 Javascript。要使您的代码正常工作,请将其移至外部脚本文件,然后将其嵌入,如下所示:

<script src="popup.js"></script>

popup.js

$(function() {
    $("#accordion").accordion({
        collapsible: true
    });
});
于 2012-07-22T10:16:48.697 回答