Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
usando index.html (página web principal, no popup.html) ¿cómo enviar datos de content.js a background.js solo después del método onClick?

El objetivo es enviar algunos datos desde la página HTML (no una ventana emergente) a la página content.js cuando se activa un clic y luego enviarlo al archivo background.js para realizar alguna función con los datos, pero estoy enfrentando algunos errores para Consíguelo.

índice.html

 <input type="text" id='fullname' /> <button onclick="sendData()">Submit</button>

Contenido.js

El método chrome.runtime.sendMessage() funciona bien cuando está dentro de document.onLoad() pero tiene un problema al llamarlo dentro de una función normal

 function sendData(){ var fullName = document.getElementById('fullname').value; chrome.runtime.sendMessage({ "message": fullName } ,(res)=>console.log(res)) }

Fondo.js

 chrome.runtime.onMessage.addListener(receiver); function receiver(data, sender, sendResponse) { if (data.message !== undefined) { chrome.pageAction.show(sender.tab.id); sendResponse(`${data.message} is submitted as your fullname`) } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Las extensiones de Chrome no le permiten tener JavaScript en línea ( documentación ).

En su lugar, asigne una identificación a su botón <button id="submitButton">Submit</button> y use addEventListener() para vincular la función sendData() como un evento.

Contenido.js

 document.addEventListener('DOMContentLoaded', function() { const button = document.getElementById('submitButton'); button.addEventListener('click', sendData); }); function sendData(){ var fullName = document.getElementById('fullname').value; chrome.runtime.sendMessage({ "message": fullName } ,(res)=>console.log(res)) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!