I wrote an extension that selects links on the page, but the problem is that it works right away.

The question is: can I make it look for links when I click a button in popup.html ?

File: contentscript.js

 $(function(){ $('a').each(function() { var a = new RegExp('/' + window.location.host + '/'); if (!a.test(this.href)) { // тут делаем что-то } }); }) 
  • The question is to add the HTML code of the button and links from popup.html - Regent
  • So your code is executed by the availability of DOM ($ (function () {...} ()). You need to bind to the button, for example: $ (function () {$ ('# button'). On ('click' , function (e) {e.preventDefault (); // your code});}); - ikenfin
  • @ikenfin so in order to properly modify the code, you need to see the HTML. #button , of course, is schematically clear, but still. - Regent
  • This code only works with the page open in the browser. - Vladimir
  • So this magic button has a unique identifier to hang a click handler on it? - Regent

0