问题
I'm trying to create an etension for Google Chrome. I am monitoring page text selection and i want the popup page to recieve the selected text when i click on the popup button.
Is there a way to pass variables to a popup? I understand, that messging doen't work for closed popups, so what should i do?
回答1:
Once a text is selected send it to a background page where you would store it in lets say textSelection
global variable. Once popup is opened you can access this variable with:
var selection = chrome.extension.getBackgroundPage().textSelection;
(you can access any variable and function from a background page directly, without requests)
回答2:
Your question can't be concisely answered, but I recommend you look here and read through some of the code samples:
http://code.google.com/chrome/extensions/messaging.html
来源:https://stackoverflow.com/questions/7217123/chrome-extension-passing-variables-to-a-popup