2012-11-06 5 views
1

가정하자 나는찾기 제목

//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에 지정된대로 URL뿐만 아니라 페이지의 제목 (뿐만 아니라 보내려는 내 크롬 확장 프로그램이 AJAX 코드가 <title> 태그입니다.) 어떻게 그 제목을 얻을 수 있습니까?

답변

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 + '"}'; 
    }); 
});