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

153
Visualizações
How to replace ads in Iframe html tag, to my custom div in chrome extension

I want to create chrome extension using simple html,css, JavaScript. which should block all frame ads on any website and replace with my ads which is created in simple html.

i try below code,

var enabled = true;
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
    if(enabled) {
        console.log("blocking:", details.url);
        chrome.tabs.executeScript(null, {file: "jquery.js"}, function() {
                chrome.tabs.executeScript(null, {
                file : content_script.js
                 
            });
             
         }); 
        //alert(newSong);
    }
     
    //$(details).closest('iframe').remove(); 
     
    return {cancel: enabled };
},
{urls: blocked_domains},
//{urls: ["<all_urls>"]}, /* replace with list of blacklisted urls */
["blocking"]
);

and content_script.js

$(window).load(function() {
     $('iframe').each(function(){
         //$(this).contents().find('img').remove();
         
         $('iframe').attr('src','https://www.w3schools.com/css/rock600x400.jpg');
     });
   
});

also tried below code but none of work,

browser.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {   //when current tab updated
    updateLabel(); 
}); 

browser.tabs.onActivated.addListener(function(activeInfo) {   //when tab shift
    browser.tabs.get(activeInfo.tabId, function(tab){
        updateLabel(); 
    });
});

please check my code or suggest me simple code.

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