Chrome扩展程序:将变量传递给弹出窗口 [英] Chrome extension: passing variables to a popup
问题描述
我正在尝试为Google Chrome创建一个扩展。我正在监视页面文本选择,我希望弹出页面能够在我点击弹出按钮时接收选定的文本。
有没有办法将变量传递给弹出窗口?我明白,这种混乱不适用于封闭的弹出窗口,所以我该怎么办?
解决方案它可以存储在后台页面中,让我们说 textSelection
全局变量。弹出窗口打开后,您可以通过以下方式访问此变量:
var selection = chrome.extension.getBackgroundPage()。textSelection;
(您可以直接从后台页面访问任何变量和函数,无需请求)
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?
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)
这篇关于Chrome扩展程序:将变量传递给弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!