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

  • Home
  • SEARCH
  • 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 7038571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:41:07+00:00 2026-05-28T01:41:07+00:00

Okay, I’m building an extension like so: has a browseraction which invokes a popup.html

  • 0

Okay, I’m building an extension like so:

  • has a browseraction which invokes a popup.html that has an input field, a submit button, and a link that invokes a javascript action
  • a background.html page that receives the input value data via popup.html and then uses them to inject custom CSS into the page

I’m using localStorage to store the input data for future use. Here’s what I need help with:

  1. run javascript in the background.html (which injects the CSS) when a button is clicked in the popup.html
  2. passing along the data from the input field in the popup.html to background.html

I scoured google source code but could not really find anything. I’m not looking to inject the CSS to every page (I know how to do that) or when the browser action icon is clicked (I know how to do that as well). I need to get that CSS injected only when a user inputs data into the popup.html and clicks on a link or button.

UPDATED:
I’m still not able to do what I need to do with this. Here’s my code:

    <script type="text/javascript">

  var bgrSize = localStorage.getItem('gridSize');
function insert(){

  chrome.tabs.executeScript(null, {code:'body{ backgroundImage:   -webkit-linear-gradient(#eee 0.05em, transparent 0.05em); backgroundPosition: 100% 0 %; backgroundSize: 100% '+ bgrSize +';}'});
}
    </script>

That’s on my background.html page. Here’s what fires from the popup.html page:

    function showGrid(){
 chrome.extension.getBackgroundPage().insert();
}

The “showGrid” function fires when a button is clicked. The gridSize data is already stored in localStorage (I have a section of the popup.html that updates to show the localStorage information).
What am I doing wrong? I just can’t figure it out. Btw, the manifest.json includes my background.html

  • 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-28T01:41:08+00:00Added an answer on May 28, 2026 at 1:41 am
    1. In popup use chrome.extension.getBackgroundPage and then execute proper function in background page. Inject data with insertCSS or executeScript
    2. Pass data thru function parameter or localStorage if you want use it later.

    Resuming:

    // popup.html
    <script>
    window.onload = function(){
    document.getElementById('my-form').addEventListener('submit', function(){
        console.log('popup');
        chrome.extension.getBackgroundPage().insert({
            param: 'example',
            input: document.getElementById('my-input').value
        });
    });
    }
    </script>
    <form id="my-form">
        <input type="text" id="my-input"/>
        <input type="submit" />
    </form>
    
    // background.html
    function insert(data){
        console.log('inserting', data.input);
        chrome.tabs.insertCSS(null, {
            code: 'a { font-size: ' + data.input + 'px;}'
        }, function(){
            console.log('inserted');
        });
    }
    
    // manifest.js
    ...
    "permissions": ["tabs", "*://*/*"]
    

    This example works – I have checked it manually 😉

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

Sidebar

Related Questions

Okay so I have a simple HTML Input fragment: <input id=txtFirstName type=text class=txtBox runat=server
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay. I know this looks like the typical Why didn't he just Google it
Okay, we know that the following two lines are equivalent - (0 == i)
Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection But
Okay, this is the case: I got a generic base-class which I need to
Okay, Now admittedly this sounds like a silly question; But, I actually have a
Okay here is my url: http://example.com/home/process_login I would like to replace the underscore with
Okay, I have hundreds of .net controls with text attributes that needs to be
Okay, so I've known about this for like 600 years now, but I've only

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.