寻找网页的标题

时间:2012-11-06 17:24:47

标签: google-chrome google-chrome-extension

假设我在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
   });
});

现在,我不仅要发送网址,还要发送网页标题(在HTML <title>标记中指定。)如何获得该标题?

1 个答案:

答案 0 :(得分: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 + '"}';
   });
});
相关问题