javascript - Set variable in content script according to message passed from BG page - chrome extension -


i've sent request content script , received response background page successfully. want set variable in content script - based on response. that's i'm having trouble. should simple enough.... guess must getting syntax wrong. here's what's in content script:

chrome.extension.sendrequest({greeting: "hello"}, function(response) {   console.log(response.farewell); if (response.farewell == "goodbye") {       waspolite = "yes"; } else if (response.farewell == "goaway") {       waspolite = "no";     } else { waspolite = "maybe"; } }); alert(waspolite); 

console shows goaway response, waspoite remains undefined.

if define:

var waspolite = ''; 

before the:

chrome.extension.... 

and it's still not alerting correct value i'd ask chrome.extension.sendrequest() function asynchronous? if may alerting waspolite before request has had time callback. @ruup on track suggesting waspolite have it's value after sendrequest has finished thereby triggering callback


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -