Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

297
Visualizações
Chrome extension + jQuery (load external content with ajax) before the DOM is loaded

I used this site to create my first Chrome extension

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

The extention is installed and running well but what I need is this:

The extension javascript script must run in the background before the DOM is loaded and the extension must pop up in certain case.

What I have now is when we click on the extension icon my code is called. But I want that extension running in the background and create a pop up in certain occasion (not only when the user click on the extension icon). For example if I try to go on google.com the script continue and do nothing but if I try to go to google2.com the pop up must appear.

To catch the current URL while browsing I use this code:

    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
    
    });

I use the code below (inside the chrome.tabs.query function):

     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");
            
        }
    });

But it doesnt works! What im doing wrong? the jQuery script is correcly loaded btw

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda