我的目标是在我的页面上打印外部页面的标题,而无需在服务器端加载前者。
目前,我正在使用jQuery和Google的搜索API。看看以下解决方案的hackyness:
//Use google search api to get page title for link
var url = "http://ajax.googleapis.com/ajax/services/search/web?q=" + **URL** + "&v=1.0&callback=?"
//Set URL for link
$("#link").attr("href", content);
//Execute google api JSON query
$.getJSON(url, function (data) {
//Insert the unformatted title of the first result into the page
$("#title").append(data.responseData.results[0].titleNoFormatting);
});
^效果很好,但仅适用于在Google上编制索引的网页,这是提交网址时的第一个结果。
谁能做得更好?