【发布时间】:2011-12-11 10:14:34
【问题描述】:
这是对my previous question 的跟进。
我正在开发一个 Chrome 扩展程序 http://ting-1.appspot.com/,它将书签页面保存到 Google App Engine 后端。查看 Chrome 网上商店,我看到扩展程序有一个“添加到 chrome”按钮。由于我的扩展程序需要与后端通信(因此用户必须有一个gmail帐户才能使用此扩展程序)我如何在扩展程序中指明使用用户名(将扩展程序添加到Chrome的人的gmail地址)来编写使用他的用户 ID 将书签添加到谷歌应用引擎?我的理解存在差距,我似乎没有在文档中找到与此问题相关的任何内容。我的background.html 在下面。谢谢。
background.html
<html>
<script>
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.getSelected(null, function(tab) {
// Send a request to the content script.
chrome.tabs.sendRequest(tab.id, {action: "getDOM"}, function(response) {
var firstParagraph = response.dom;
console.log("background -- before *console.log(response.dom)*")
console.log("this is *console.log(response.dom)*: " + response.dom)
console.log("background -- after *console.log(response.dom)*")
//}); moved to end to get the variable firstParagraph
var formData = new FormData();
formData.append("url", tab.url);
formData.append("title", tab.title);
formData.append("pitch", firstParagraph);
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://ting-1.appspot.com/submithandlertest", true);
xhr.onreadystatechange = function (aEvt) {
if (xhr.readyState == 4) {
if (xhr.status == 200){
console.log("request 200-OK");
chrome.browserAction.setBadgeText ( { text: "done" } );
setTimeout(function () {
chrome.browserAction.setBadgeText( { text: "" } );
}, 2000);
}else{
console.log("connection error");
chrome.browserAction.setBadgeText ( { text: "ERR" } );
}
}
};
xhr.send(formData);
}); //chrome.tabs.sendRequest
});
});
</script>
</html>
【问题讨论】:
标签: javascript google-app-engine google-chrome-extension