铬扩展概率

时间:2012-11-25 22:17:53

标签: jquery google-chrome-extension

我的清单代码是

 {
  "name": "Sample",
  "description": "Sample demonstration",
  "version": "0.1",
  "minimum_chrome_version": "16.0.884",
  "permissions": [
    "experimental", "tabs","<all_urls>"
  ],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "manifest_version": 2
}

我的popup.html代码是

<html>
<head>
<script src='popup.js'></script>
<script src='jquery.js'></script>
</head>
<body>
</body>
</html>

popup.js代码

$(document).ready(function() {
     $.post('http://localhost/LinkBook/index.php', {}, function(res){
                       console.log('res');
                    });   
    });

但它不起作用。帮助我。

1 个答案:

答案 0 :(得分:1)

我为所有邮寄申请编写了一个样本框架,这些申请经过了充分的测试和工作多年;您可以将其用作参考并更正代码

的manifest.json

{
  "name": "Sample",
  "description": "Sample demonstration",
  "version": "0.1",
  "minimum_chrome_version": "16.0.884",
  "permissions": [
    "experimental", "tabs","<all_urls>"
  ],
  "browser_action": {
    "default_icon": "icon.jpg",
    "default_popup": "popup.html"
  },
  "manifest_version": 2
}

popup.html

<html>
<head>
<script src='transaction.js'></script>
</head>
<body>
</body>
</html>

popup.js

function searchquotes(){

var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function(data) {
    if (xhr.readyState == 4) {
      if (xhr.status == 200) {
            console.log("Response is recieved");
        }
      } else {
        //callback(null);
      }
    }

var url = 'https://'+'somedomain.com/sompage.php';
xhr.open('POST', url, true);
xhr.send();

}
window.onload = searchquotes;

jquery版本

IMP:你的代码中不能有<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>,下载jquery并将其放在你的根文件夹中,有关详细信息,请查看this(https://developer.chrome.com/extensions /contentSecurityPolicy.html)

的manifest.json

{
  "name": "Sample",
  "description": "Sample demonstration",
  "version": "0.1",
  "minimum_chrome_version": "16.0.884",
  "permissions": [
    "experimental", "tabs","<all_urls>"
  ],
  "browser_action": {
    "default_icon": "icon.jpg",
    "default_popup": "popup.html"
  },
  "manifest_version": 2
}

popup.html

<html>
<head>
<script src='transaction.js'></script>
<script src='jquery.js'></script>
</head>
<body>
</body>
</html>

transaction.js

$(document).ready(function() {
     $.post("http://somedomain.com/sompage.php', {}, function(res){
                       console.log(res);
                    });   
    });