0

I am working on chrome extension where user will enter the value in the form (extension form) and clicking on the submit button the value should fill to the current browser tab form's textbox. but i am not able to pass the value

here is the all details : manifest.json

{
  "name": "My First Extension",
  "version": "1.0",
  "manifest_version": 2,
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",
  "permissions": [
      "tabs", "http://*/*"
    ],
    "content_scripts": [
      {
        "matches": ["*******weburl*********"],
        "js": ["jquery.js","content.js"],
        "run_at": "document_start"
      }
  ],
  "web_accessible_resources": ["inject.js"]
}

popup.html

<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

</head>
<body style="width: 400px">
<div>
  <div>Search Bookmarks: <input id="search"></div>
<input type="button" name="submit" value="submit" id="submit">
 </div>
</body>
</html>

content.js

(function (chrome) {
    var js = document.createElement('script');
    js.type = 'text/javascript';
    js.src = chrome.extension.getURL('inject.js');
   // document.getElementsByTagName('head')[0].appendChild(js);
(document.head || document.documentElement).appendChild(js);
}(chrome));

and here is my inject.js file

$(document).ready(function(){
    // alert('Here');
    $("#submit").click(function(){
        document.getElementById('email').value = 'REWRWRE';
    });
})

The id email is my web url form's email address but it is not filling the value after click. if i just passed the value on load it is filling that field but not after the click.

Thanks in advance!!

  • Why are you injecting a script into the page context? You should be able to make the change of the `document.getElementById('email').value` from the content script. It appears that you are trying to access the `'#submit'` button that is in your *popup.html* from within the script which you are injecting into the webpage context. That makes no sense at all. You *certainly* can't access your popup page from that context. You have only included jQuery in your *popup.html*, you will need some of your own code too. – Makyen Nov 25 '16 at 23:41
  • Please include a functional amount of the webpage you are trying to change (even if it is just a prototype which includes the `id="emai"` element). This will allow people to write answers without having to make up that code, which will also help keep any answer consistent with each other, or at least working from the same start. – Makyen Nov 25 '16 at 23:51

0 Answers0