使用chrome扩展插件将chrome中访问的URL插入MySQL数据库

Inserting URLs visited in chrome to a MySQL db using Chrome Extension

本文关键字:chrome URL 插入 数据库 MySQL 扩展 插件 使用 访问      更新时间:2023-09-26

我想要一个Chrome扩展,它将不断在MySQL表中插入用户访问的URL。

background.html

<script>
var myURL = "nourl";
chrome.tabs.getSelected(null, function(tab) {
  myURL = tab.url;
});
dataparam = "url="+myURL;
    $.ajax({
        type: "POST",
        url: "http://domainname.com/insertdb.php",
        data: dataparam,
        error:function() {
                alert("sorry")
        },
        success: function(html) {
            alert(html);
        }
    });

</script>

insertdb.php

<?php
$val=$_REQUEST['url'];
// Inserting $val in the db code goes here.
?>

我是javascript的新手,这段代码似乎不起作用。任何帮助都将不胜感激。提前非常感谢。

您需要获得跨来源的权限。

http://developer.chrome.com/extensions/xhr.html