Appeler des fonctions JS depuis input sur extension chrome
Fermé
mahdiweb
Messages postés
11
Date d'inscription
mardi 20 septembre 2022
Statut
Membre
Dernière intervention
26 octobre 2022
-
20 sept. 2022 à 13:14
mahdiweb - 21 sept. 2022 à 09:07
mahdiweb - 21 sept. 2022 à 09:07
A voir également:
- Appeler des fonctions JS depuis input sur extension chrome
- Appeler en privé - Guide
- Changer extension fichier - Guide
- Mise a jour chrome - Accueil - Applications & Logiciels
- Chrome cast sur tv - Guide
- Extension odt - Guide
1 réponse
j'avance un peux après quelques modification j'ai maintenant les codes suivants:
popup.html
-------------------
<!doctype html> <html> <head> <style> body { min-width: 120px; overflow-x: hidden; font-family: Arial, sans-serif; font-size: 12px; } input, textarea { width: 140px; } input#save { font-weight: bold; width: auto; } </style> </head> <body> <h1>GRC</h1> <center><form> <div> <label><b>Veuillez saisir un code</b></label> <input name="inpt" id="inpt" autocomplete="off"/> <p> <button id="btn">Enter</button> <script src="popup.js"></script> </p> </div> </form></center> </body> </html>
popup.js
-----------------------
const button = document.getElementById('btn'); const input = document.getElementById('inpt'); button.onclick = async evt => { const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); await chrome.scripting.executeScript({ target: { tabId: tab.id }, files: ['injector.js'], }); await chrome.scripting.executeScript({ target: { tabId: tab.id }, func: inPage, args: [input.value], }); window.close(); }; function inPage(popup) { functions[popup]();
injector.js
----------------
functions = { 1 : function(){alert(1);}, 2 : function(){alert(2);}, 3 : function(){alert(3);}, 4 : function(){alert(4);}, 5 : function(){alert(5);}, 6 : function(){alert(6);}, }
mais ça ne marche toujours pas si vous avez des propositions svp et merci.