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

295
Views
Extensión de Chrome + jQuery (cargar contenido externo con ajax) antes de cargar el DOM

Usé este sitio para crear mi primera extensión de Chrome

https://www.sitepoint.com/create-chrome-extension-10-minutes-flat/

La extensión está instalada y funcionando bien, pero lo que necesito es esto:

El script javascript de extensión debe ejecutarse en segundo plano antes de que se cargue el DOM y la extensión debe aparecer en ciertos casos.

Lo que tengo ahora es que cuando hacemos clic en el icono de la extensión se llama mi código. Pero quiero que la extensión se ejecute en segundo plano y cree una ventana emergente en determinadas ocasiones (no solo cuando el usuario haga clic en el icono de la extensión). Por ejemplo, si trato de ir a google.com, el script continúa y no hace nada, pero si trato de ir a google2.com, debe aparecer la ventana emergente.

Para capturar la URL actual mientras navego, uso este código:

 chrome.tabs.query({'active': true, 'lastFocusedWindow': true, 'currentWindow': true}, function (tabs) { var url = tabs[0].url; const arrayURL= url .split("/"); var BrowsedURL=arrayURL[2]; alert(BrowsedURL); // I have now the variable BrowsedURL, now I want to do an ajax call on a certain website with that parameter. If the website reply the source code 0, the script will do nothing. If the website reply with the source code 1, the extension pop up appear. // I know that I can interact with the popup.html page because when I try // jQuery("#div1").text("some text"); // the "some text" appear on the popup.html page });

Uso el siguiente código (dentro de la función chrome.tabs.query):

 jQuery.ajax({ type: "GET",url: "https://example.com/?myvariable="+BrowsedURL,async: true, data: {url: url, response: response },success: function(resp) { if(resp==0){ // do nothing } if(resp==1){ // div1 is a div in the popup.html page jQuery("#div1").text("some text"); } });

¡Pero no funciona! ¿Qué estoy haciendo mal? el script jQuery se carga correctamente por cierto

about 4 years ago · Juan Pablo Isaza
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!