如何将EventListener添加到Amazon提交按钮

时间:2016-10-31 18:50:02

标签: javascript html google-chrome google-chrome-extension

我正在尝试将亚马逊的提交按钮作为我的活动,以便我可以阅读该人正在搜索的内容,但我无法让它工作。我不确定如何确切地指出按钮。

myscript.js

function getProduct(){
    console.log('getProduct');
    var textbox = document.getElementById('twotabsearchtextbox').value;
    console.log(textbox.value);
    init(); 
}

function init(){
    console.log('in init');
    var i = document.getElementsByClassName('nav-input');
    console.log(i[0].value);
    console.log(i[1].value);
    i[0].addEventListener('onclick', getProduct );
}
function testen(){
    console.log('test');
}
window.onload = init;

的manifest.json

{
    "name": "Bachelortest",
    "description": "teste",
    "version": "1.0",
    "manifest_version":2,

    "browser_action":{
    "default_icon":"icon.png",
    "default_popup":"popup.html"
    },
    "permissions":["tabs", "storage", "activeTab" ,"geolocation"],

    "background": {
    "scripts": ["background.js"]
    },

      "content_scripts": [
    {
      "matches": ["https://*/*","http://*/*", "https://www.amazon.de/*"],
      "js": ["jquery-1.12.3.min.js","myscript.js"]
    }
  ]

}

1 个答案:

答案 0 :(得分:1)

您应该将事件监听器添加到表单提交中:

document.querySelector('.nav-searchbar').addEventListener('submit', event => {
  console.log(document.querySelector('#twotabsearchtextbox').value)
})