Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda