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

152
Views
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
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!