1

假设我的 Chrome 扩展中有这个 AJAX 代码

//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
   });
});

现在,我不仅要发送 URL,还要发送页面标题(在 HTML<title>标记中指定)。我怎样才能获得该标题?

4

1 回答 1

1

您可以尝试使用document.title

//bind to all links
$('a').click( function() {
   //get the url
   var url = $(this).prop('href');
   var title = document.title;
   //send the url to your server
   $.ajax({
        type: "POST",
        url: "http://yourserver.com/process.php",
        // Haven't tested this yet :)
        data: '{"url": "' + url + '", "title": "' + title + '"}';
   });
});
于 2012-11-06T17:29:45.467 回答