I am a newbie, so excuse me if this is a silly question ..
So what I was trying is to get the title of a URL using JQuery/JS. I dont want to load the content of the
Something like this should work:
$.ajax({
url: externalUrl,
async: true,
success: function(data) {
var matches = data.match(/(.*?)<\/title>/);
alert(matches[0]);
}
});
TheSuperTramp is correct, above will not work if externalUrl is outside of your domain. Instead create this php file get_external_content.php:
(.+)<\/title>/',$html,$matches);
$title = $matches[1];
echo json_encode(array("url" => $url, "title" => $title));
then in javascript:
function getTitle(externalUrl){
var proxyurl = "http://localhost/get_external_content.php?url=" + externalUrl;
$.ajax({
url: proxyurl,
async: true,
success: function(response) {
alert(response);
},
error: function(e) {
alert("error! " + e);
}
});
}