0

I cannot get the event handler to fire. I already moved it out of an inline script. It won't load the external scripts in the form it is now. I tried loading the scripts in the manifest but the click handler still does not fire. In the current state of the below code, it seems like the script files don't even load for some reason.

Here is the manifest

    {
      "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
    }

Here is the html file

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

Here is 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");
        }
      });

    }

I am using jQuery 1.2. Please let me know if you have any ideas. Thank you.

Drew Gallagher
  • 746
  • 2
  • 9
  • 18
  • 2
    Possible duplicate of [How can I access the page's DOM rather than the popup's DOM, using jQuery if possible?](http://stackoverflow.com/questions/4532236/how-can-i-access-the-pages-dom-rather-than-the-popups-dom-using-jquery-if-pos) – wOxxOm Aug 11 '16 at 19:51
  • The extension popup is a separate document just like any other browser tab, it has its own DOM totally unrelated to the webpage. See [extension architecture](https://developer.chrome.com/extensions/overview#arch) documentation. You can find lots of examples by googling for [chrome extension access webpage from popup](https://www.google.com/#q=chrome%20extension%20access%20webpage%20from%20popup). – wOxxOm Aug 11 '16 at 19:53

0 Answers0