Chrome extension: passing variables to a popup

♀尐吖头ヾ 提交于 2019-12-21 02:49:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!