I want the below code to execute when I push the button I have added to my chrome browser through my开发者_如何学C extension:
<script>
var formData = new FormData();
var html = document.innerHTML;
formData.append("time", "12:00:00");
formData.append("html",document.getElementsByTagName('html')[0].innerHTML);
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://www.mywebsite.com/index");
xhr.send(formData);
</script>
my issues is I have no idea where does this go? background html? manifest? I cant understand how it works even after reading the document about the architecture can anyone help me?.
This code should go into background page. In order for it to work you need to add https://www.mywebsite.com
to domain permissions first. It is all explained here with examples.
To catch browser action button click:
//background.html
chrome.browserAction.onClicked.addListener(function(tab) {
var formData = new FormData();
...
});
This will work only if you don't have a popup defined.
精彩评论