Javascript + Chrome Tabs Api - Can't Get Tab's Url
I have the following piece of code and the problem is that the callback from chrome.tabs.getSelected is evaluated after the request which is send with empty url. How can I solve th
Solution 1:
Welcome to Asynchronous Programming
function send() {
chrome.tabs.getSelected(null, function(tab) {
var client = new XMLHttpRequest();
client.onreadystatechange = function() {
if(this.readyState == 4) {
alert(this.status);
}
}
client.open("POST", "http://myurl");
client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
client.send(tab.url);
});
}
Post a Comment for "Javascript + Chrome Tabs Api - Can't Get Tab's Url"