Chrome扩展程序onClick侦听器未在弹出窗口中触发

时间:2016-08-11 18:13:07

标签: javascript jquery html google-chrome-extension event-listener

我无法触发事件处理程序。我已经把它从内联脚本中删除了。它不会以现在的形式加载外部脚本。我尝试在清单中加载脚本,但点击处理程序仍然不会触发。在以下代码的当前状态下,似乎脚本文件由于某种原因甚至没有加载。

这是清单

    {
      "name": "Click to execute",
      "version": "1.0",

      "permissions": [
        "https://www.netflix.com/*"
      ],

      "web_accessible_resources": [
          "alert.js"
        ],

      "icons": {
        "48": "icon.png"
      },


      "permissions": [
        "tabs", "<all_urls>", "http://localhost/*"
      ],

      "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html"
      },
        "manifest_version": 2
    }

这是html文件             

    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
            input[type="text"] {
                padding: 3px;
                margin: 8px;
                text-align: center;
                font-size: 18px;
            }

            input[type="submit"] {
                border: 0;
                padding: 10px 35px;
                margin: 8px auto;
                ;
                display: block;
            }
        </style>
    </head>

    <body>
        <script src="jquery.js"></script>
        <script src="alert.js"></script>
        <h1>Enter Info</h1>
        <form>
            <input type="text" name="Title" placeholder="Enter Title" required="true">
            <input type="number" name="Skip" placeholder="Enter Skip Time" required="true">
            <input type="number" name="Intro" placeholder="Enter Intro Length" required="true">
            <input id="clickMe" type="button" value="Click me" name="submit">
        </form>
    </body>

    </html>

这是alert.js

    $(document).ready(function(){
      var skip=0;
      var tvLong = $("span").text();
      var locNum = tvLong.search("Season");
      var tvName = tvLong.slice(0, locNum);
      var tvSeason = tvLong.slice(locNum + 7, locNum + 8);
      var tvEpisode = tvLong.slice(locNum + 14, locNum + 15);
      var time = parseInt(skip);
      var title = tvName + "."+tvSeason+"."+tvEpisode;
    setInterval(function(){
      if($("video").get(0)){
        skip=$("video").get(0).currentTime;
      }
    },100);


    //alert(title+ "  " + time);
    console.log("loaded");

    var button=document.getElementById('clickMe');
    if(button){
      button.onclick=function(){
        console.log("clicked");

      };
    }


    // $("#clickMe").click(function() {
    //
    // })

    });


    function callAjax() {

      //-----------------------------------------------------------------------
      // 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/
      //-----------------------------------------------------------------------
      $.ajax({
        url: 'conscript.php',                  //the script to call to get data
        data: {Title:"Archer.2.9", Skip:115, Intro:34},                        //you can insert url argumnets here to pass to api.php
        type: "POST",                   //for example "id=5&parent=6"
        dataType: 'json',                //data format
        success: function(data)          //on recieve of reply
        {
          console.log(data);
          //Set output element html
          //recommend reading up on jquery selectors they are awesome
          // http://api.jquery.com/category/selectors/
        },
        error: function(error)
        {
          console.log("ERROR");
        }
      });

    }

我正在使用jQuery 1.2。如果您有任何想法,请告诉我。谢谢。

0 个答案:

没有答案