【发布时间】:2011-12-04 00:00:17
【问题描述】:
我正在开发一个简单的书签应用程序来学习 Google App Engine。此时,我将 url 复制并粘贴到 http://ting-1.appspot.com/submit 中,它有一个带有 url 字段的表单。由于这很麻烦,我想添加一个 chrome 扩展。我刚刚更改了hello world example,所以现在我使用此代码(as explained here) 获得标签的网址:
<script>
window.addEventListener("load", windowLoaded, false);
function windowLoaded() {
chrome.tabs.getSelected(null, function(tab) {
document.getElementById('currentLink').innerHTML = tab.url;
tabUrl = tab.url;
});
}
document.write(tabUrl)
</script>
如何将tabUrl 传递给http://ting-1.appspot.com/submit?
谢谢!
更新
我使用的background.html改编自Mohamed Mansour's answer:
<script>
//React when a browser action's icon is clicked.
chrome.browserAction.onClicked.addListener(function(tab) {
//this gets the url and the title
chrome.tabs.getSelected(null, function(tab) {
tabUrl = tab.url
tabTitle = tab.title
//this posts the data to the bookmarking app
var formData = new FormData();
formData.append("url", tabUrl);
formData.append("title", tabTitle);
formData.append("pitch", "this is a note");
formData.append("user_tag_list", "tag1, tag2");
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://ting-1.appspot.com/submithandlertest");
xhr.send(formData);
});
});
</script>
【问题讨论】:
标签: javascript google-app-engine google-chrome-extension