将Chrome扩展程序连接到服务器

问题描述:

我知道谷歌浏览器扩展程序可以有一些HTML和JavaScript。但我想将它连接到我的服务器。当用户在浏览某个URL时单击该扩展上的按钮时,该URL将添加到服务器上的数据库中。是否有可能实现这个功能?

I know that Google Chrome extension can have some HTML and JavaScript. But I would like to connect it to my server. When the user clicks a button on the extension when he's navigating a certain URL, the URL is added to the database on the server. Is it possible to implement this functionality?

是的,这是可能的。只需添加事件处理程序,以便单击URL时。然后可以将数据异步发送回服务器。希望你通知你的插件客户你打算跟踪他们的所有点击。

Yes it is possible. Just add event handlers for when urls are clicked. You can then send the data back to your server asynchronously. Hopefully you are informing your plugin customers that you intend to track all their clicks.

我建议使用像jQuery这样的库。

I would recommend using a library like jQuery for this.

//bind to all links
$('a').click( function() {
   //get the url
   var url = $(this).prop('href');
   //send the url to your server
   $.ajax({
        type: "POST",
        url: "http://yourserver.com/process.php",
        data: "url=" + url
   });
});

您需要使用php或asp等服务器端语言解析发布的网址并将其存储在您的数据库。

You will need a server side language like php or asp to parse the posted url and store it in your database.