Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7643667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:30:14+00:00 2026-05-31T09:30:14+00:00

When a user clicks on the browser icon for the extension, it brings up

  • 0

When a user clicks on the browser icon for the extension, it brings up the Popup that has been defined.

I need to create a toggle button to turn on/off a stylesheet for a specific page/domain when a user clicks a button that is within the popup.

For example, when a user uses the Adblock extension, when the user clicks the browser icon, it brings up the popup, which has a series of links. One such link is “don’t run on this page”, which then changes to “enable” which the user can click to turn it back on.

Another example (much better example): Classic Popup blocker has a button on the popup that says “add this page to blacklist” and once clicked changes to “remove from blacklist”.

The classic popup blocker is generally the functionality I want for my extension (it’s not doing anything with ads or popup blocking, that was just an example), so that when a user clicks the button on the popup it will turn a stylesheet on or off that I have written and saved as a .css file in the extension.

I hope I have made this clear enough to understand.


SCREENS

Here is a photoshopped picture that I made so that you can see exactly what I am trying to do:

photoshopped screenshot toggle on


and photoshopped again to see what should happen once you click the buttons:

photoshopped screenshot toggle off


  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:30:15+00:00Added an answer on May 31, 2026 at 9:30 am

    You can use the chrome.tabs.executeScript method to dynamically inject/remove CSS (requires the tabs permission in manifest.json):

    chrome.tabs.executeScript(null, {code:
        'document.documentElement.setAttribute("RWchooseStyle", "style1.css");'
    }, function() {
        chrome.tabs.executeScript(null, {file: 'myscript.js'});
    });
    

    In myscript.js, detect whether you have already inserted CSS. If not, add a new <style> or link element, and assign an id to it. Otherwise, replace the style sheet.

    Example of myscript.js:

    var selectedStyle = document.documentElement.getAttribute('RWchooseStyle');
    var id, link;
    if (selectedStyle) {
        id = 'RW_style_' + selectedStyle.replace(/\W/g,'');   // Sanitize id
        // Remove previous sheet, if available.
        link = document.getElementById(id);
        if (link) {
            link.parentNode.removeChild(link);
        }
    }
    if (id) {
        // Insert new sheet
        link = document.createElement('link');
        link.rel = 'stylesheet';
        link.type = 'text/css';
        link.href = chrome.extension.getURL(selectedStyle);
        link.id = id;
        (document.head||document.documentElement).appendChild(link);
    }
    
    // Remove temporary attribute
    document.documentElement.removeAttribute('RWChooseStyle');
    

    In this example, the CSS files have to be defined in your extensions directory. Of course, you can also use <style> instead if <link>, and dynamically set the style’s content.

    Note: Do not forget to add the style sheet to the web_accessible_resources section of the manifest file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to detect when the user clicks on the browser's back button?
When the user clicks a button, I want his browser to automatically scroll to
I have page where RSS icon is present. I want that when user clicks
I want to stop the browser request, when user clicks on any button from
How do I write a chrome extension such that every time a user clicks
Details: Only disable after user clicks the submit button, but before the posting back
When a user clicks a submit button I want the form to be submitted.
As soon as the user clicks the delete button my jQuery script asks the
When the user clicks the "Maximized"/"Restore" or "Minimized" buttons of the browser window, is
I am creating a Chrome Extension that upon clicking the extension icon will present

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.