search

Home  >  Q&A  >  body text

javascript - How to bind functions to custom buttons in chrome plug-in?

RT, there is a chrome plug-in, there is a button in the html page of the plug-in, click the button, how to call the function defined in the plug-in and the js file?

In the index.html page of the plug-in:

<button  onclick='test()'>开始获取</button>

In the main.js file of the plug-in:

function test(){
  console.log('come from test');
}

Link main.js in index.html

//index.html在html文件夹中,注意这里要使用相对路径                                                                 
<script src="../script/main.js" charset="utf-8"></script>

It is not feasible to directly bind the test() function to the button, so how to call it

Supplementary solutions

Right-click on the plug-in, check the plug-in console, and find an error

Be sure to note that the plug-in console and the page console are not in the same place

曾经蜡笔没有小新曾经蜡笔没有小新2692 days ago789

reply all(1)I'll reply

  • 漂亮男人

    漂亮男人2017-07-05 10:49:37

    Have you linked main.js in index.html

    reply
    0
  • Cancelreply