google chrome extension- popup page not showing correctly

本小妞迷上赌 提交于 2019-12-17 21:14:27

问题


I am working to create a Google Chrome Extension- in this extension, there is a popup page that uses Accordion- via Jquery UI.

Now, I have correctly defined the popup.html file in manifest.json, and added the code of "start" theme of Jquery UI to the popup.html file.

However when I click on the button in toolbar which should display the popup, then all sections of the accordion are being shown opened- and the accordion is not being shown at all-- all I can see is the plain text for various sections of the accordion.

Given below is the code of my 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
 }
}

Also, given below is a portion of the code of my popup.html file--

<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>

What am I doing wrong here? How do I resolve this error?


回答1:


When "manifest_version": 2 is specified, the default Content security policy restrictions are set. One of the consequences is that inline JavaScript is not evaluated.

There's no way to enable inline Javascript. To get your code to work, move it to an external script file, and embed it, as follows:

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

popup.js:

$(function() {
    $("#accordion").accordion({
        collapsible: true
    });
});


来源:https://stackoverflow.com/questions/11599365/google-chrome-extension-popup-page-not-showing-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!