khex khex - 4 months ago 46
Javascript Question

Fetch meta-tags from url only by jQuery

Now a lot of scripts to facebook-style fetching data from url, but all of them work only in combination of jQuery and PHP. Is it possible to fetch url only by jQuery?

I have found here how to get mata-tags of page by:

$('meta[name=description]').attr("content");
$("meta[property=og:title]").attr("content", document.title);


But how correctly insert this query in jQuery.get() to get text values?

$.get('http://www.imdb.com/title/tt1375666/', function(data) {
$('meta[name=adescription]').attr("content");
});


And if the most popular sites use OpenGraph should I look in the direction of jQuery.getJSON()?

Answer

Use the html data retrieved from URL

$.get('http://www.guardian.co.uk/culture/2012/jun/21/jimmy-carr-apologises-error-tax', 
function(data) {
   $(data).find('meta[name=adescription]').attr("content");
});
Comments