Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 2 of 2

This is a discussion on Pass data from background to tab script. within the Plugins Development section, part of the Chrome Plugins category: Hi My extension uses omnibar keyword. When user enters a specific keyword and a command, i open a javascript popup ...


  1. #1
    irmn is offline Junior Member
    Join Date
    Mar 2011
    Posts
    12

    Default Pass data from background to tab script.

    Hi

    My extension uses omnibar keyword. When user enters a specific keyword and a command, i open a javascript popup in the current tab by using the following code from my background page..

    Code:
    chrome.tabs.executeScript(null, {file: "popup.js"});
    Where popup.js file contains the code to create and display the popup.

    But, the javascript popup needs to show some dynamic text. So, i need to pass that dynamic text from the background page to popup.js file. How do i do that?

    Thanks.

  2. #2
    PAEz's Avatar
    PAEz is offline Moderator
    Join Date
    Aug 2009
    Location
    Australia
    Posts
    656

    Default

    Typically you use the messaging api to communicate between different parts of an extension.....
    http://code.google.com/chrome/extensions/messaging.html

    But this is one of those times where you dont need that.
    In your case Id do something like this.....
    background.js
    Code:
      theCode='var dynamictext = "Bunyips are ugly";';
      chrome.tabs.executeScript(null, {code:theCode,allFrames:false}, function(){
      chrome.tabs.executeScript(null, {file:'content.js',allFrames:false}); 
      }  
      );
    content.js
    Code:
    alert(dynamictext);
    ....saves a bit of effort

Similar Threads

  1. background stretching
    By Iruini626 in forum Themes Development
    Replies: 19
    Last Post: 01-13-2012, 11:52 PM
  2. Transparent Background
    By Nud3l in forum Plugins Development
    Replies: 0
    Last Post: 11-09-2010, 11:15 AM
  3. Displaying my Cookie data instead of the website
    By Osmosis in forum Chrome Troubleshooting
    Replies: 1
    Last Post: 11-09-2010, 12:45 AM
  4. Write data on HTML
    By pornima in forum Chrome Troubleshooting
    Replies: 0
    Last Post: 01-20-2010, 01:04 PM
  5. Clear Browsing Data.
    By budchekov in forum Chrome Troubleshooting
    Replies: 1
    Last Post: 12-13-2009, 04:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •